-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.kt
More file actions
98 lines (83 loc) · 2.52 KB
/
test.kt
File metadata and controls
98 lines (83 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import datkt.bytes.bytesFrom
import datkt.tape.test
fun main(args: Array<String>) {
test("bytesFrom(vararg bytes: Number): ByteArray") { t ->
run {
val bytes = bytesFrom(0xfe, 0xed, 0xbe, 0xef)
t.equal(bytes[0].toInt() and 0xff, 0xfe)
t.equal(bytes[1].toInt() and 0xff, 0xed)
t.equal(bytes[2].toInt() and 0xff, 0xbe)
t.equal(bytes[3].toInt() and 0xff, 0xef)
}
run {
val bytes = bytesFrom(*arrayOf(0xfe, 0xed, 0xbe, 0xef))
t.equal(bytes[0].toInt() and 0xff, 0xfe)
t.equal(bytes[1].toInt() and 0xff, 0xed)
t.equal(bytes[2].toInt() and 0xff, 0xbe)
t.equal(bytes[3].toInt() and 0xff, 0xef)
}
t.end()
}
test("bytesFrom(bytes: ByteArray): ByteArray") { t ->
val bytes = bytesFrom(bytesFrom(0xfe, 0xed, 0xbe, 0xef))
t.equal(bytes[0].toInt() and 0xff, 0xfe)
t.equal(bytes[1].toInt() and 0xff, 0xed)
t.equal(bytes[2].toInt() and 0xff, 0xbe)
t.equal(bytes[3].toInt() and 0xff, 0xef)
t.end()
}
test("bytesFrom(bytes: Array<Number>): ByteArray") { t ->
val bytes = bytesFrom(arrayOf(0xfe, 0xed, 0xbe, 0xef))
t.equal(bytes[0].toInt() and 0xff, 0xfe)
t.equal(bytes[1].toInt() and 0xff, 0xed)
t.equal(bytes[2].toInt() and 0xff, 0xbe)
t.equal(bytes[3].toInt() and 0xff, 0xef)
t.end()
}
test("bytesFrom(bytes: String): ByteArray") { t ->
val bytes = bytesFrom("feedbeef")
t.equal(bytes[0].toInt() and 0xff, 0x66)
t.equal(bytes[1].toInt() and 0xff, 0x65)
t.equal(bytes[2].toInt() and 0xff, 0x65)
t.equal(bytes[3].toInt() and 0xff, 0x64)
t.equal(bytes[4].toInt() and 0xff, 0x62)
t.equal(bytes[5].toInt() and 0xff, 0x65)
t.equal(bytes[6].toInt() and 0xff, 0x65)
t.equal(bytes[7].toInt() and 0xff, 0x66)
t.end()
}
test("bytesFrom(size: Number): ByteArray") { t ->
run {
val bytes = bytesFrom(0)
t.equal(bytes.size, 0)
}
run {
val bytes = bytesFrom(16)
t.equal(bytes.size, 16)
}
t.end()
}
test("bytesFrom(size: Char): ByteArray") { t ->
run {
val bytes = bytesFrom('0')
t.equal(bytes.size, '0'.toInt())
}
run {
val bytes = bytesFrom('a')
t.equal(bytes.size, 0x61)
}
run {
val bytes = bytesFrom('c')
t.equal(bytes.size, 'c'.toInt())
}
t.end()
}
test("bytesFrom(bytes: Any? = null): ByteArray") { t ->
t.equal(bytesFrom().size, 0)
t.equal(bytesFrom(null).size, 0)
t.equal(bytesFrom("").size, 0)
t.equal(bytesFrom(fun() { }).size, 0)
t.end()
}
datkt.tape.collect()
}