forked from picolove/picolove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
123 lines (106 loc) · 2.92 KB
/
test.lua
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local api = require("api")
log = print
-- test api
assert(api.min(1, 2) == 1)
assert(api.min(2, 1) == 1)
assert(api.min(-1, 2) == -1)
assert(api.min(2, -1) == -1)
assert(api.min("1", "2") == 1)
assert(api.min("2", "1") == 1)
assert(api.min("-1", "2") == -1)
assert(api.min("2", "-1") == -1)
assert(api.min(1, nil) == 0)
assert(api.min(nil, 1) == 0)
assert(api.min(-1, nil) == -1)
assert(api.min(nil, -1) == -1)
assert(api.min(1, "X") == 0)
assert(api.min("X", 1) == 0)
assert(api.min(-1, "X") == -1)
assert(api.min("X", -1) == -1)
assert(api.min(nil, nil) == 0)
assert(api.max(1, 2) == 2)
assert(api.max(2, 1) == 2)
assert(api.max(-1, 2) == 2)
assert(api.max(2, -1) == 2)
assert(api.max("1", "2") == 2)
assert(api.max("2", "1") == 2)
assert(api.max("-1", "2") == 2)
assert(api.max("2", "-1") == 2)
assert(api.max(1, nil) == 1)
assert(api.max(nil, 1) == 1)
assert(api.max(-1, nil) == 0)
assert(api.max(nil, -1) == 0)
assert(api.max(1, "X") == 1)
assert(api.max("X", 1) == 1)
assert(api.max(-1, "X") == 0)
assert(api.max("X", -1) == 0)
assert(api.max(nil, nil) == 0)
assert(api.mid(1, 2, 3) == 2)
assert(api.mid(1, 3, 2) == 2)
assert(api.mid(2, 1, 3) == 2)
assert(api.mid(2, 3, 1) == 2)
assert(api.mid(3, 1, 2) == 2)
assert(api.mid(3, 2, 1) == 2)
assert(api.atan2(1, 0) == 0)
assert(api.atan2(0, -1) == 0.25)
assert(api.atan2(-1, 0) == 0.5)
assert(api.atan2(0, 1) == 0.75)
assert(bit.band(0x01, bit.lshift(1, 0)) ~= 0)
assert(bit.band(0x02, bit.lshift(1, 1)) ~= 0)
assert(bit.band(0x04, bit.lshift(1, 2)) ~= 0)
assert(bit.band(0x05, bit.lshift(1, 2)) ~= 0)
assert(bit.band(0x05, bit.lshift(1, 0)) ~= 0)
assert(bit.band(0x05, bit.lshift(1, 3)) == 0)
local iter = api.all({nil, nil, 11, nil, 22, 33, 33, b = 42, 44})
assert(iter() == 11)
assert(iter() == 22)
assert(iter() == 33)
assert(iter() == 33)
assert(iter() == 44)
assert(iter() == nil)
local array = {}
assert(api.add(nil, 1) == nil)
assert(api.add(array, 1) == 1)
assert(api.add(array, 2) == 2)
assert(api.add(array, 3) == 3)
assert(api.add(array, 1) == 1)
assert(api.add(array, 2) == 2)
assert(api.add(array, 3) == 3)
assert(array[1] == 1)
assert(array[2] == 2)
assert(array[3] == 3)
assert(array[4] == 1)
assert(array[5] == 2)
assert(array[6] == 3)
assert(array[7] == nil)
local array2 = {1, 2, 3, 1, 2, 3}
assert(array[1] == 1)
assert(array[2] == 2)
assert(array[3] == 3)
assert(array[4] == 1)
assert(array[5] == 2)
assert(array[6] == 3)
assert(array[7] == nil)
assert(api.del(array, 1) == 1)
assert(array[1] == 2)
assert(array[2] == 3)
assert(array[3] == 1)
assert(array[4] == 2)
assert(array[5] == 3)
assert(array[6] == nil)
assert(api.del(array, 3) == 3)
assert(array[1] == 2)
assert(array[2] == 1)
assert(array[3] == 2)
assert(array[4] == 3)
assert(array[5] == nil)
assert(api.del(array, 3) == 3)
assert(array[1] == 2)
assert(array[2] == 1)
assert(array[3] == 2)
assert(array[4] == nil)
assert(api.del(array, 3) == nil)
assert(array[1] == 2)
assert(array[2] == 1)
assert(array[3] == 2)
assert(array[4] == nil)