Skip to content

Commit fc8e166

Browse files
authored
Sync Forth (exercism#2871)
This updates the Forth exercise to sync with the problem specifications.
1 parent 85652b5 commit fc8e166

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

exercises/practice/forth/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"aadityakulkarni",
77
"FridaTveit",
88
"hgvanpariya",
9+
"jagdish-15",
910
"jmrunkle",
1011
"kytrinyx",
1112
"lemoncurry",

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

Lines changed: 18 additions & 0 deletions
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/src/test/java/ForthEvaluatorTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public void testErrorIfAdditionAttemptedWithOneNumberOnTheStack() {
4848
.withMessage("Addition requires that the stack contain at least 2 values");
4949
}
5050

51+
@Disabled("Remove to run test")
52+
@Test
53+
public void testAdditionForMoreThanTwoValuesOnTheStack() {
54+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 +")))
55+
.containsExactly(1, 5);
56+
}
57+
5158
@Disabled("Remove to run test")
5259
@Test
5360
public void testTwoNumbersCanBeSubtracted() {
@@ -72,6 +79,13 @@ public void testErrorIfSubtractionAttemptedWithOneNumberOnTheStack() {
7279
.withMessage("Subtraction requires that the stack contain at least 2 values");
7380
}
7481

82+
@Disabled("Remove to run test")
83+
@Test
84+
public void testSubtractionForMoreThanTwoValuesOnTheStack() {
85+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 -")))
86+
.containsExactly(1, 9);
87+
}
88+
7589
@Disabled("Remove to run test")
7690
@Test
7791
public void testTwoNumbersCanBeMultiplied() {
@@ -94,6 +108,13 @@ public void testErrorIfMultiplicationAttemptedWithOneNumberOnTheStack() {
94108
.withMessage("Multiplication requires that the stack contain at least 2 values");
95109
}
96110

111+
@Disabled("Remove to run test")
112+
@Test
113+
public void testMultiplicationForMoreThanTwoValuesOnTheStack() {
114+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 *")))
115+
.containsExactly(1, 6);
116+
}
117+
97118
@Disabled("Remove to run test")
98119
@Test
99120
public void testTwoNumbersCanBeDivided() {
@@ -130,6 +151,13 @@ public void testErrorIfDivisionAttemptedWithOneNumberOnTheStack() {
130151
.withMessage("Division requires that the stack contain at least 2 values");
131152
}
132153

154+
@Disabled("Remove to run test")
155+
@Test
156+
public void testDivisionForMoreThanTwoValuesOnTheStack() {
157+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 /")))
158+
.containsExactly(1, 4);
159+
}
160+
133161
@Disabled("Remove to run test")
134162
@Test
135163
public void testCombinedAdditionAndSubtraction() {
@@ -142,6 +170,18 @@ public void testCombinedMultiplicationAndDivision() {
142170
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("2 4 * 3 /"))).containsExactly(2);
143171
}
144172

173+
@Disabled("Remove to run test")
174+
@Test
175+
public void testCombinedMultiplicationAndAddition() {
176+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 * +"))).containsExactly(13);
177+
}
178+
179+
@Disabled("Remove to run test")
180+
@Test
181+
public void testCombinedAdditionAndMultiplication() {
182+
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 + *"))).containsExactly(7);
183+
}
184+
145185
@Disabled("Remove to run test")
146186
@Test
147187
public void testDupCopiesAValueOnTheStack() {

0 commit comments

Comments
 (0)