Skip to content

Commit 80a7fe4

Browse files
authored
sync tests forth (#365)
1 parent 39432ef commit 80a7fe4

File tree

2 files changed

+97
-48
lines changed

2 files changed

+97
-48
lines changed

exercises/practice/forth/.meta/tests.toml

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ description = "addition -> errors if there is nothing on the stack"
2424
[06efb9a4-817a-435e-b509-06166993c1b8]
2525
description = "addition -> errors if there is only one value on the stack"
2626

27+
[1e07a098-c5fa-4c66-97b2-3c81205dbc2f]
28+
description = "addition -> more than two values on the stack"
29+
2730
[09687c99-7bbc-44af-8526-e402f997ccbf]
2831
description = "subtraction -> can subtract two numbers"
2932

@@ -33,6 +36,9 @@ description = "subtraction -> errors if there is nothing on the stack"
3336
[b3cee1b2-9159-418a-b00d-a1bb3765c23b]
3437
description = "subtraction -> errors if there is only one value on the stack"
3538

39+
[2c8cc5ed-da97-4cb1-8b98-fa7b526644f4]
40+
description = "subtraction -> more than two values on the stack"
41+
3642
[5df0ceb5-922e-401f-974d-8287427dbf21]
3743
description = "multiplication -> can multiply two numbers"
3844

@@ -42,6 +48,9 @@ description = "multiplication -> errors if there is nothing on the stack"
4248
[8ba4b432-9f94-41e0-8fae-3b3712bd51b3]
4349
description = "multiplication -> errors if there is only one value on the stack"
4450

51+
[5cd085b5-deb1-43cc-9c17-6b1c38bc9970]
52+
description = "multiplication -> more than two values on the stack"
53+
4554
[e74c2204-b057-4cff-9aa9-31c7c97a93f5]
4655
description = "division -> can divide two numbers"
4756

@@ -57,12 +66,21 @@ description = "division -> errors if there is nothing on the stack"
5766
[d5547f43-c2ff-4d5c-9cb0-2a4f6684c20d]
5867
description = "division -> errors if there is only one value on the stack"
5968

69+
[f224f3e0-b6b6-4864-81de-9769ecefa03f]
70+
description = "division -> more than two values on the stack"
71+
6072
[ee28d729-6692-4a30-b9be-0d830c52a68c]
6173
description = "combined arithmetic -> addition and subtraction"
6274

6375
[40b197da-fa4b-4aca-a50b-f000d19422c1]
6476
description = "combined arithmetic -> multiplication and division"
6577

78+
[f749b540-53aa-458e-87ec-a70797eddbcb]
79+
description = "combined arithmetic -> multiplication and addition"
80+
81+
[c8e5a4c2-f9bf-4805-9a35-3c3314e4989a]
82+
description = "combined arithmetic -> addition and multiplication"
83+
6684
[c5758235-6eef-4bf6-ab62-c878e50b9957]
6785
description = "dup -> copies a value on the stack"
6886

exercises/practice/forth/forth.test

+79-48
Original file line numberDiff line numberDiff line change
@@ -9,242 +9,273 @@ source testHelpers.tcl
99
############################################################
1010
source "forth.tcl"
1111

12-
test forth-1 "numbers just get pushed onto the stack" -body {
12+
test forth-1 "parsing and numbers: numbers just get pushed onto the stack" -body {
1313
evalForth "1 2 3 4 5"
1414
} -returnCodes ok -result {1 2 3 4 5}
1515

1616
skip forth-2
17-
test forth-2 "pushes negative numbers onto the stack" -body {
17+
test forth-2 "parsing and numbers: pushes negative numbers onto the stack" -body {
1818
evalForth "-1 -2 -3 -4 -5"
1919
} -returnCodes ok -result {-1 -2 -3 -4 -5}
2020

2121
skip forth-3
22-
test forth-3 "can add two numbers" -body {
22+
test forth-3 "addition: can add two numbers" -body {
2323
evalForth "1 2 +"
2424
} -returnCodes ok -result {3}
2525

2626
skip forth-4
27-
test forth-4 "errors if there is nothing on the stack" -body {
27+
test forth-4 "addition: errors if there is nothing on the stack" -body {
2828
evalForth "+"
2929
} -returnCodes error -result "empty stack"
3030

3131
skip forth-5
32-
test forth-5 "errors if there is only one value on the stack" -body {
32+
test forth-5 "addition: errors if there is only one value on the stack" -body {
3333
evalForth "1 +"
3434
} -returnCodes error -result "only one value on the stack"
3535

36+
skip forth-5a
37+
test forth-5a "addition: more than one value on the stack" -body {
38+
evalForth "1 2 3 +"
39+
} -returnCodes ok -result {1 5}
40+
3641
skip forth-6
37-
test forth-6 "can subtract two numbers" -body {
42+
test forth-6 "subtraction: can subtract two numbers" -body {
3843
evalForth "3 4 -"
3944
} -returnCodes ok -result {-1}
4045

4146
skip forth-7
42-
test forth-7 "errors if there is nothing on the stack" -body {
47+
test forth-7 "subtraction: errors if there is nothing on the stack" -body {
4348
evalForth "-"
4449
} -returnCodes error -result "empty stack"
4550

4651
skip forth-8
47-
test forth-8 "errors if there is only one value on the stack" -body {
52+
test forth-8 "subtraction: errors if there is only one value on the stack" -body {
4853
evalForth "1 -"
4954
} -returnCodes error -result "only one value on the stack"
5055

56+
skip forth-8a
57+
test forth-8a "subtraction: more than one value on the stack" -body {
58+
evalForth "1 12 3 -"
59+
} -returnCodes ok -result {1 9}
60+
5161
skip forth-9
52-
test forth-9 "can multiply two numbers" -body {
62+
test forth-9 "multiplication: can multiply two numbers" -body {
5363
evalForth "2 4 *"
5464
} -returnCodes ok -result {8}
5565

5666
skip forth-10
57-
test forth-10 "errors if there is nothing on the stack" -body {
67+
test forth-10 "multiplication: errors if there is nothing on the stack" -body {
5868
evalForth "*"
5969
} -returnCodes error -result "empty stack"
6070

6171
skip forth-11
62-
test forth-11 "errors if there is only one value on the stack" -body {
72+
test forth-11 "multiplication: errors if there is only one value on the stack" -body {
6373
evalForth "1 *"
6474
} -returnCodes error -result "only one value on the stack"
6575

76+
skip forth-11a
77+
test forth-11a "multiplication: more than one value on the stack" -body {
78+
evalForth "1 2 3 *"
79+
} -returnCodes ok -result {1 6}
80+
6681
skip forth-12
67-
test forth-12 "can divide two numbers" -body {
82+
test forth-12 "division: can divide two numbers" -body {
6883
evalForth "12 3 /"
6984
} -returnCodes ok -result {4}
7085

7186
skip forth-13
72-
test forth-13 "performs integer division" -body {
87+
test forth-13 "division: performs integer division" -body {
7388
evalForth "8 3 /"
7489
} -returnCodes ok -result {2}
7590

7691
skip forth-14
77-
test forth-14 "errors if dividing by zero" -body {
92+
test forth-14 "division: errors if dividing by zero" -body {
7893
evalForth "4 0 /"
7994
} -returnCodes error -result "divide by zero"
8095

8196
skip forth-15
82-
test forth-15 "errors if there is nothing on the stack" -body {
97+
test forth-15 "division: errors if there is nothing on the stack" -body {
8398
evalForth "/"
8499
} -returnCodes error -result "empty stack"
85100

86101
skip forth-16
87-
test forth-16 "errors if there is only one value on the stack" -body {
102+
test forth-16 "division: errors if there is only one value on the stack" -body {
88103
evalForth "1 /"
89104
} -returnCodes error -result "only one value on the stack"
90105

106+
skip forth-16a
107+
test forth-16a "division: more than one value on the stack" -body {
108+
evalForth "1 12 3 /"
109+
} -returnCodes ok -result {1 4}
110+
111+
91112
skip forth-17
92-
test forth-17 "addition and subtraction" -body {
113+
test forth-17 "combined arithmetic: addition and subtraction" -body {
93114
evalForth "1 2 + 4 -"
94115
} -returnCodes ok -result {-1}
95116

96117
skip forth-18
97-
test forth-18 "multiplication and division" -body {
118+
test forth-18 "combined arithmetic: multiplication and division" -body {
98119
evalForth "2 4 * 3 /"
99120
} -returnCodes ok -result {2}
100121

122+
skip forth-18a
123+
test forth-18a "combined arithmetic: multiplication and addition" -body {
124+
evalForth "1 3 4 * +"
125+
} -returnCodes ok -result {13}
126+
127+
skip forth-18b
128+
test forth-18b "combined arithmetic: addition and multiplication" -body {
129+
evalForth "1 3 4 + *"
130+
} -returnCodes ok -result {7}
131+
101132
skip forth-19
102-
test forth-19 "copies a value on the stack" -body {
133+
test forth-19 "dup: copies a value on the stack" -body {
103134
evalForth "1 dup"
104135
} -returnCodes ok -result {1 1}
105136

106137
skip forth-20
107-
test forth-20 "copies the top value on the stack" -body {
138+
test forth-20 "dup: copies the top value on the stack" -body {
108139
evalForth "1 2 dup"
109140
} -returnCodes ok -result {1 2 2}
110141

111142
skip forth-21
112-
test forth-21 "errors if there is nothing on the stack" -body {
143+
test forth-21 "dup: errors if there is nothing on the stack" -body {
113144
evalForth "dup"
114145
} -returnCodes error -result "empty stack"
115146

116147
skip forth-22
117-
test forth-22 "removes the top value on the stack if it is the only one" -body {
148+
test forth-22 "drop: removes the top value on the stack if it is the only one" -body {
118149
evalForth "1 drop"
119150
} -returnCodes ok -result {}
120151

121152
skip forth-23
122-
test forth-23 "removes the top value on the stack if it is not the only one" -body {
153+
test forth-23 "drop: removes the top value on the stack if it is not the only one" -body {
123154
evalForth "1 2 drop"
124155
} -returnCodes ok -result {1}
125156

126157
skip forth-24
127-
test forth-24 "errors if there is nothing on the stack" -body {
158+
test forth-24 "drop: errors if there is nothing on the stack" -body {
128159
evalForth "drop"
129160
} -returnCodes error -result "empty stack"
130161

131162
skip forth-25
132-
test forth-25 "swaps the top two values on the stack if they are the only ones" -body {
163+
test forth-25 "swap: swaps the top two values on the stack if they are the only ones" -body {
133164
evalForth "1 2 swap"
134165
} -returnCodes ok -result {2 1}
135166

136167
skip forth-26
137-
test forth-26 "swaps the top two values on the stack if they are not the only ones" -body {
168+
test forth-26 "swap: swaps the top two values on the stack if they are not the only ones" -body {
138169
evalForth "1 2 3 swap"
139170
} -returnCodes ok -result {1 3 2}
140171

141172
skip forth-27
142-
test forth-27 "errors if there is nothing on the stack" -body {
173+
test forth-27 "swap: errors if there is nothing on the stack" -body {
143174
evalForth "swap"
144175
} -returnCodes error -result "empty stack"
145176

146177
skip forth-28
147-
test forth-28 "errors if there is only one value on the stack" -body {
178+
test forth-28 "swap: errors if there is only one value on the stack" -body {
148179
evalForth "1 swap"
149180
} -returnCodes error -result "only one value on the stack"
150181

151182
skip forth-29
152-
test forth-29 "copies the second element if there are only two" -body {
183+
test forth-29 "over: copies the second element if there are only two" -body {
153184
evalForth "1 2 over"
154185
} -returnCodes ok -result {1 2 1}
155186

156187
skip forth-30
157-
test forth-30 "copies the second element if there are more than two" -body {
188+
test forth-30 "over: copies the second element if there are more than two" -body {
158189
evalForth "1 2 3 over"
159190
} -returnCodes ok -result {1 2 3 2}
160191

161192
skip forth-31
162-
test forth-31 "errors if there is nothing on the stack" -body {
193+
test forth-31 "over: errors if there is nothing on the stack" -body {
163194
evalForth "over"
164195
} -returnCodes error -result "empty stack"
165196

166197
skip forth-32
167-
test forth-32 "errors if there is only one value on the stack" -body {
198+
test forth-32 "over: errors if there is only one value on the stack" -body {
168199
evalForth "1 over"
169200
} -returnCodes error -result "only one value on the stack"
170201

171202
skip forth-33
172-
test forth-33 "can consist of built-in words" -body {
203+
test forth-33 "user-defined words: can consist of built-in words" -body {
173204
evalForth ": dup-twice dup dup ;\n1 dup-twice"
174205
} -returnCodes ok -result {1 1 1}
175206

176207
skip forth-34
177-
test forth-34 "execute in the right order" -body {
208+
test forth-34 "user-defined words: execute in the right order" -body {
178209
evalForth ": countup 1 2 3 ;\ncountup"
179210
} -returnCodes ok -result {1 2 3}
180211

181212
skip forth-35
182-
test forth-35 "can override other user-defined words" -body {
213+
test forth-35 "user-defined words: can override other user-defined words" -body {
183214
evalForth ": foo dup ;\n: foo dup dup ;\n1 foo"
184215
} -returnCodes ok -result {1 1 1}
185216

186217
skip forth-36
187-
test forth-36 "can override built-in words" -body {
218+
test forth-36 "user-defined words: can override built-in words" -body {
188219
evalForth ": swap dup ;\n1 swap"
189220
} -returnCodes ok -result {1 1}
190221

191222
skip forth-37
192-
test forth-37 "can override built-in operators" -body {
223+
test forth-37 "user-defined words: can override built-in operators" -body {
193224
evalForth ": + * ;\n3 4 +"
194225
} -returnCodes ok -result {12}
195226

196227
skip forth-38
197-
test forth-38 "can use different words with the same name" -body {
228+
test forth-38 "user-defined words: can use different words with the same name" -body {
198229
evalForth ": foo 5 ;\n: bar foo ;\n: foo 6 ;\nbar foo"
199230
} -returnCodes ok -result {5 6}
200231

201232
skip forth-39
202-
test forth-39 "can define word that uses word with the same name" -body {
233+
test forth-39 "user-defined words: can define word that uses word with the same name" -body {
203234
evalForth ": foo 10 ;\n: foo foo 1 + ;\nfoo"
204235
} -returnCodes ok -result {11}
205236

206237
skip forth-40
207-
test forth-40 "cannot redefine non-negative numbers" -body {
238+
test forth-40 "user-defined words: cannot redefine non-negative numbers" -body {
208239
evalForth ": 1 2 ;"
209240
} -returnCodes error -result "illegal operation"
210241

211242
skip forth-41
212-
test forth-41 "cannot redefine negative numbers" -body {
243+
test forth-41 "user-defined words: cannot redefine negative numbers" -body {
213244
evalForth ": -1 2 ;"
214245
} -returnCodes error -result "illegal operation"
215246

216247
skip forth-42
217-
test forth-42 "errors if executing a non-existent word" -body {
248+
test forth-42 "user-defined words: errors if executing a non-existent word" -body {
218249
evalForth "foo"
219250
} -returnCodes error -result "undefined operation"
220251

221252
skip forth-43
222-
test forth-43 "DUP is case-insensitive" -body {
253+
test forth-43 "case-insensitivity: DUP is case-insensitive" -body {
223254
evalForth "1 DUP Dup dup"
224255
} -returnCodes ok -result {1 1 1 1}
225256

226257
skip forth-44
227-
test forth-44 "DROP is case-insensitive" -body {
258+
test forth-44 "case-insensitivity: DROP is case-insensitive" -body {
228259
evalForth "1 2 3 4 DROP Drop drop"
229260
} -returnCodes ok -result {1}
230261

231262
skip forth-45
232-
test forth-45 "SWAP is case-insensitive" -body {
263+
test forth-45 "case-insensitivity: SWAP is case-insensitive" -body {
233264
evalForth "1 2 SWAP 3 Swap 4 swap"
234265
} -returnCodes ok -result {2 3 4 1}
235266

236267
skip forth-46
237-
test forth-46 "OVER is case-insensitive" -body {
268+
test forth-46 "case-insensitivity: OVER is case-insensitive" -body {
238269
evalForth "1 2 OVER Over over"
239270
} -returnCodes ok -result {1 2 1 2 1}
240271

241272
skip forth-47
242-
test forth-47 "user-defined words are case-insensitive" -body {
273+
test forth-47 "case-insensitivity: user-defined words are case-insensitive" -body {
243274
evalForth ": foo dup ;\n1 FOO Foo foo"
244275
} -returnCodes ok -result {1 1 1 1}
245276

246277
skip forth-48
247-
test forth-48 "definitions are case-insensitive" -body {
278+
test forth-48 "case-insensitivity: definitions are case-insensitive" -body {
248279
evalForth ": SWAP DUP Dup dup ;\n1 swap"
249280
} -returnCodes ok -result {1 1 1 1}
250281

0 commit comments

Comments
 (0)