initial: varing and smarting packing tools
This commit is contained in:
commit
0f9702b1dc
15 files changed
+914
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package bintools
|
||||
|
||||
import com.icodici.ubdata.Smartint
|
||||
import net.sergeych.bintools.encodeToHex
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SmartintTest {
|
||||
|
||||
fun testValue(x: Long) {
|
||||
assertEquals(x.toULong(), Smartint.decode(Smartint.encode(x.toULong())))
|
||||
assertEquals(x, Smartint.decodeSigned(Smartint.encodeSigned(x)))
|
||||
println("+ ${x}: ${Smartint.encode(x.toULong()).encodeToHex()}")
|
||||
}
|
||||
|
||||
fun testAround(bits: Int) {
|
||||
println("----- $bits -----")
|
||||
val window = 5
|
||||
var median: Long = (1.toULong() shl bits).toLong()
|
||||
for( x in (median-2)..(median+2)) {
|
||||
testValue(x)
|
||||
}
|
||||
median = median * 3 / 2
|
||||
for( x in (median-5)..(median+5)) {
|
||||
testValue(x)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun encode() {
|
||||
for( i in 0..70) testValue(i.toLong())
|
||||
testAround(6)
|
||||
testAround(14)
|
||||
testAround(22)
|
||||
testAround(29)
|
||||
testAround(36)
|
||||
testValue(-1)
|
||||
// testAround(28)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun decode() {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user