upgraded to k1.8, upgraded stools, added more docs on codecs
This commit is contained in:
1 parent
8fb052c4f9
commit
6e65a216c5
4 files changed
+68
-33
No files matched your search
@@ -10,7 +10,7 @@ import kotlin.test.assertEquals
|
||||
|
||||
class SmartintTest {
|
||||
|
||||
inline fun <reified T:Number>testValue(x: T) {
|
||||
inline fun <reified T : Number> testValue(x: T) {
|
||||
assertEquals(x, Smartint.decode(Smartint.encode(x)))
|
||||
println("+ ${x}: ${Smartint.encode(x).encodeToHex()}")
|
||||
}
|
||||
@@ -19,12 +19,12 @@ class SmartintTest {
|
||||
println("----- $bits -----")
|
||||
val window = 5
|
||||
var median: Long = (1.toULong() shl bits).toLong()
|
||||
for( x in (median-2)..(median+2)) {
|
||||
for (x in (median - 2)..(median + 2)) {
|
||||
testValue(x)
|
||||
testValue(-x)
|
||||
}
|
||||
median = median * 3 / 2
|
||||
for( x in (median-5)..(median+5)) {
|
||||
for (x in (median - 5)..(median + 5)) {
|
||||
testValue(x)
|
||||
testValue(-x)
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class SmartintTest {
|
||||
|
||||
@Test
|
||||
fun encode() {
|
||||
for( i in 0..70) testValue(i.toLong())
|
||||
for (i in 0..70) testValue(i.toLong())
|
||||
testAround(6)
|
||||
testAround(14)
|
||||
testAround(22)
|
||||
@@ -42,14 +42,30 @@ class SmartintTest {
|
||||
// testAround(28)
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
fun compareTest() {
|
||||
for( x in listOf<ULong>(0uL, 1uL, 66uL, 129uL, 219uL, 0x1122uL, 0xFFEEuL, 0xAAbbCCdduL,
|
||||
0x1111222233334444uL, (1UL shl 63))) {
|
||||
// for( x in listOf<ULong>(0uL, 1uL, 66uL, 129uL, 219uL, 0x1122uL, 0xFFEEuL, 0xAAbbCCdduL,
|
||||
// 0x1111222233334444uL, (1UL shl 63))) {
|
||||
var lastDelta = 0
|
||||
for (x in 0..3000000000) {
|
||||
val n1 = Varint.encode(x).size
|
||||
val n2 = Smartint.encode(x).size
|
||||
val delta = n1 - n2
|
||||
if (delta != lastDelta) {
|
||||
when {
|
||||
delta < 0 -> println("LOSS: $delta from $x")
|
||||
delta > 0 -> println("GAIN: $delta from $x")
|
||||
delta == 0 -> println("SAME: from $x")
|
||||
}
|
||||
lastDelta = delta
|
||||
}
|
||||
// for( x in listOf<ULong>(0uL, 1uL, (1UL shl 17)+11UL)) {
|
||||
// 0x1111222233334444uL, (1UL shl 63))) {
|
||||
// 1--12--23--34--4
|
||||
println("--- $x / 0x${x.encodeToHex(8)}")
|
||||
println("V: ${Varint.encode(x).encodeToHex()}")
|
||||
println("S: ${Smartint.encode(x).encodeToHex()}")
|
||||
// println("--- $x / 0x${x.encodeToHex(8)}")
|
||||
// println("V: ${Varint.encode(x).encodeToHex()}")
|
||||
// println("S: ${Smartint.encode(x).encodeToHex()}")
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user