-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathIntTests.res
168 lines (163 loc) · 4.6 KB
/
IntTests.res
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
open RescriptCore
let eq = (a, b) => a == b
let catch = f =>
try {
let _ = f()
failwith("no exception raised")
} catch {
| Error.Error(err) => err
}
Test.run(__POS_OF__("range - positive, increasing"), Int.range(3, 6), eq, [3, 4, 5])
Test.run(__POS_OF__("range - negative, increasing"), Int.range(-3, -1), eq, [-3, -2])
Test.run(__POS_OF__("range - cross-zero, incresing"), Int.range(-1, 2), eq, [-1, 0, 1])
Test.run(__POS_OF__("range - start == end"), Int.range(3, 3), eq, [])
Test.run(__POS_OF__("range - positive, decreasing"), Int.range(3, 1), eq, [3, 2])
Test.run(__POS_OF__("range - negative, decreasing"), Int.range(-1, -3), eq, [-1, -2])
Test.run(
__POS_OF__("range - positive, increasing, step 2"),
Int.range(3, 6, ~options={step: 2}),
eq,
[3, 5],
)
Test.run(
__POS_OF__("range + positive, increasing, step 2"),
Int.range(3, 7, ~options={step: 2}),
eq,
[3, 5],
)
Test.run(
__POS_OF__("range + positive, increasing, step 2"),
Int.range(3, 8, ~options={step: 2}),
eq,
[3, 5, 7],
)
Test.run(
__POS_OF__("range - negative, increasing, step 2"),
Int.range(-6, -3, ~options={step: 2}),
eq,
[-6, -4],
)
Test.run(
__POS_OF__("range - positive, increasing, step 0"),
catch(() => Int.range(3, 6, ~options={step: 0})),
eq,
Error.RangeError.make("Incorrect range arguments"),
)
Test.run(__POS_OF__("range - start == end, step 0"), Int.range(3, 3, ~options={step: 0}), eq, [])
Test.run(
__POS_OF__("range + positive, increasing, step -1"),
Int.range(3, 6, ~options={step: -1}),
eq,
[],
)
Test.run(
__POS_OF__("range + positive, decreasing, step 1"),
Int.range(6, 3, ~options={step: 1}),
eq,
[],
)
Test.run(
__POS_OF__("range + positive, decreasing, step -2"),
Int.range(6, 3, ~options={step: -2}),
eq,
[6, 4],
)
Test.run(
__POS_OF__("range + positive, increasing, step -2"),
Int.range(6, 2, ~options={step: -2}),
eq,
[6, 4],
)
Test.run(
__POS_OF__("range + positive, increasing, step -2"),
Int.range(6, 1, ~options={step: -2}),
eq,
[6, 4, 2],
)
Test.run(
__POS_OF__("range + negative, decreasing, step -2"),
Int.range(-3, -6, ~options={step: -2}),
eq,
[-3, -5],
)
Test.run(
__POS_OF__("range - positive, increasing, step 2, inclusive"),
Int.range(3, 6, ~options={step: 2, inclusive: true}),
eq,
[3, 5],
)
Test.run(
__POS_OF__("range + positive, increasing, step 2, inclusive"),
Int.range(3, 7, ~options={step: 2, inclusive: true}),
eq,
[3, 5, 7],
)
Test.run(
__POS_OF__("range + positive, increasing, step 2, inclusive"),
Int.range(3, 8, ~options={step: 2, inclusive: true}),
eq,
[3, 5, 7],
)
Test.run(
__POS_OF__("range - negative, increasing, step 2, inclusive"),
Int.range(-6, -3, ~options={step: 2, inclusive: true}),
eq,
[-6, -4],
)
Test.run(
__POS_OF__("range - positive, increasing, step 0, inclusive"),
catch(() => Int.range(3, 6, ~options={step: 0, inclusive: true})),
eq,
Error.RangeError.make("Incorrect range arguments"),
)
Test.run(
__POS_OF__("range - start == end, step 0, inclusive"),
Int.range(3, 3, ~options={step: 0, inclusive: true}),
eq,
[3],
)
Test.run(
__POS_OF__("range + positive, increasing, step -1, inclusive"),
Int.range(3, 6, ~options={step: -1, inclusive: true}),
eq,
[],
)
Test.run(
__POS_OF__("range + positive, decreasing, step 1, inclusive"),
Int.range(6, 3, ~options={step: 1, inclusive: true}),
eq,
[],
)
Test.run(
__POS_OF__("range + positive, decreasing, step -2, inclusive"),
Int.range(6, 3, ~options={step: -2, inclusive: true}),
eq,
[6, 4],
)
Test.run(
__POS_OF__("range + positive, increasing, step -2, inclusive"),
Int.range(6, 2, ~options={step: -2, inclusive: true}),
eq,
[6, 4, 2],
)
Test.run(
__POS_OF__("range + positive, increasing, step -2, inclusive"),
Int.range(6, 1, ~options={step: -2, inclusive: true}),
eq,
[6, 4, 2],
)
Test.run(
__POS_OF__("range + negative, decreasing, step -2, inclusive"),
Int.range(-3, -6, ~options={step: -2, inclusive: true}),
eq,
[-3, -5],
)
Test.run(__POS_OF__("clamp"), Int.clamp(42), eq, 42)
Test.run(__POS_OF__("clamp - < min"), Int.clamp(~min=50, 42), eq, 50)
Test.run(__POS_OF__("clamp - > min"), Int.clamp(~min=40, 42), eq, 42)
Test.run(__POS_OF__("clamp - < max"), Int.clamp(~max=50, 42), eq, 42)
Test.run(__POS_OF__("clamp - > max"), Int.clamp(~max=40, 42), eq, 40)
Test.run(__POS_OF__("clamp - < min, < max"), Int.clamp(~min=50, ~max=60, 42), eq, 50)
Test.run(__POS_OF__("clamp - < min, > max"), Int.clamp(~min=50, ~max=40, 42), eq, 50) // min wins
Test.run(__POS_OF__("clamp - > min, < max"), Int.clamp(~min=40, ~max=60, 42), eq, 42)
Test.run(__POS_OF__("clamp - > min, > max"), Int.clamp(~min=40, ~max=40, 42), eq, 40)