import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant import net.sergeych.crypto2.initCrypto import net.sergeych.utools.nowToSeconds import net.sergeych.utools.pack import net.sergeych.utools.unpack import kotlin.test.Test import kotlin.test.assertEquals import kotlin.time.Duration.Companion.microseconds class PackTest { inline fun check(x: T?) { assertEquals(x, unpack(pack(x))) } @Test fun testNullPack() = runTest { initCrypto() val d = pack("Hello") assertEquals(6, d.size) check(1) check(2L) check(1.00) check("hello") check(null) check(null) } @Test fun testTimePack() = runTest { initCrypto() val t1 = nowToSeconds() val t2 = t1 + 1.microseconds assertEquals(t1, unpack(pack(t2))) } }