fixed bugs in types, added more tests
This commit is contained in:
1 parent
0e8f3daf99
commit
0b1cd2d9cf
5 files changed
+70
-14
No files matched your search
@@ -16,7 +16,8 @@ data class Foobar1(val bar: Int, val foo: Int = 117)
|
||||
|
||||
@Serializable
|
||||
@ExtendableFormat
|
||||
data class Foobar2(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
data class Foobar2(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
|
||||
@Serializable
|
||||
@Framed
|
||||
@ExtendableFormat
|
||||
@@ -26,17 +27,18 @@ data class FoobarF1(val bar: Int, val foo: Int = 117)
|
||||
@Framed
|
||||
@ExtendableFormat
|
||||
@SerialName("bipack.FoobarF1")
|
||||
data class FoobarF2(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
data class FoobarF2(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
|
||||
@Serializable
|
||||
@Framed
|
||||
@ExtendableFormat
|
||||
data class FoobarF3(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
data class FoobarF3(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
|
||||
@Serializable
|
||||
@Framed
|
||||
@ExtendableFormat
|
||||
@CrcProtected()
|
||||
data class FoobarFP1(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
data class FoobarFP1(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
|
||||
class BipackEncoderTest {
|
||||
|
||||
@@ -61,6 +63,7 @@ class BipackEncoderTest {
|
||||
assertEquals(-1, c.other)
|
||||
assertEquals(a.bar, c.bar)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun encodeFramed() {
|
||||
val a = FoobarF1(42)//, "bum")
|
||||
@@ -103,13 +106,15 @@ class BipackEncoderTest {
|
||||
val u: UInt,
|
||||
@Unsigned
|
||||
val i: Int,
|
||||
val k: UInt = 3u)
|
||||
val k: UInt = 3u,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun testByteArray() {
|
||||
// val z = Foobar1(42)//, "bum")
|
||||
// println(BipackEncoder.encode(z).toDump())
|
||||
|
||||
val x = byteArrayOf(1,2,3)
|
||||
val x = byteArrayOf(1, 2, 3)
|
||||
var d = BipackEncoder.encode(x)
|
||||
println(d.toDump())
|
||||
assertEquals(0x0c, d[0])
|
||||
@@ -128,4 +133,54 @@ class BipackEncoderTest {
|
||||
|
||||
assertEquals(f, BipackDecoder.decode(d))
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Types1(
|
||||
val i: Int = 7,
|
||||
val f: Float = 1f/3f,
|
||||
val d: Double = 1.0/3.0,
|
||||
val b: Boolean = true,
|
||||
val s: String = "жёпа",
|
||||
val ba: ByteArray = byteArrayOf(1,2,3),
|
||||
val ch: Char = 'Ы',
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || this::class != other::class) return false
|
||||
|
||||
other as Types1
|
||||
|
||||
if (i != other.i) return false
|
||||
if (f != other.f) return false
|
||||
if (d != other.d) return false
|
||||
if (b != other.b) return false
|
||||
if (s != other.s) return false
|
||||
if (!ba.contentEquals(other.ba)) return false
|
||||
if (ch != other.ch) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = i
|
||||
result = 31 * result + f.hashCode()
|
||||
result = 31 * result + d.hashCode()
|
||||
result = 31 * result + b.hashCode()
|
||||
result = 31 * result + s.hashCode()
|
||||
result = 31 * result + ba.contentHashCode()
|
||||
result = 31 * result + ch.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTypes() {
|
||||
// val t1 = Types1(10, 1.0f / 10.0f, 1.0 / 10.0, true, "жесть", byteArrayOf(1, 2, 3), 'Ы')
|
||||
val t1 = Types1(f=17f/7f)
|
||||
val d = BipackEncoder.encode(t1)
|
||||
// println(d.toDump())
|
||||
// println(t1)
|
||||
// println(d.decodeFromBipack<Types1>())
|
||||
assertEquals(t1, d.decodeFromBipack())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user