This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathrepeat-loops.lcb
More file actions
61 lines (50 loc) · 2.09 KB
/
repeat-loops.lcb
File metadata and controls
61 lines (50 loc) · 2.09 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
module __VMTEST.repeat_loops
public handler TestRepeatForUpTo()
-- This test ensures that repeat up to loops perform the correct number of
-- iterations, motivated by a 'double' issue on emscripten. Rather than
-- use numbers to test, we use a string which accumulates a new char for
-- each iteration ensuring that the method of testing is entirely distinct
-- from what is being tested.
variable tLoopCount as String
variable tCount as Number
put the empty string into tLoopCount
repeat with tCount from 1 up to 12
put "X" after tLoopCount
end repeat
test "from 1 up to 12 gives 12 iterations" when tLoopCount is "XXXXXXXXXXXX"
put the empty string into tLoopCount
repeat with tCount from 1 up to 12 by 2
put "X" after tLoopCount
end repeat
test "from 1 up to 12 by 2 gives 6 iterations" when tLoopCount is "XXXXXX"
put the empty string into tLoopCount
repeat with tCount from 1 up to 12 by 0.5
put "X" after tLoopCount
end repeat
test "from 1 up to 12 by 0.5 gives 24 iterations" when tLoopCount is "XXXXXXXXXXXXXXXXXXXXXXX"
end handler
public handler TestRepeatForDownTo()
-- This test ensures that repeat down to loops perform the correct number of
-- iterations, motivated by a 'double' issue on emscripten. Rather than
-- use numbers to test, we use a string which accumulates a new char for
-- each iteration ensuring that the method of testing is entirely distinct
-- from what is being tested.
variable tLoopCount as String
variable tCount as Number
put the empty string into tLoopCount
repeat with tCount from 12 down to 1
put "X" after tLoopCount
end repeat
test "from 12 down to 1 gives 12 iterations" when tLoopCount is "XXXXXXXXXXXX"
put the empty string into tLoopCount
repeat with tCount from 12 down to 1 by -2
put "X" after tLoopCount
end repeat
test "from 12 down to 1 by 2 gives 6 iterations" when tLoopCount is "XXXXXX"
put the empty string into tLoopCount
repeat with tCount from 12 down to 1 by -0.5
put "X" after tLoopCount
end repeat
test "from 12 down to 1 by 0.5 gives 24 iterations" when tLoopCount is "XXXXXXXXXXXXXXXXXXXXXXX"
end handler
end module