Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/practice/forth/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"aadityakulkarni",
"FridaTveit",
"hgvanpariya",
"jagdish-15",
"jmrunkle",
"kytrinyx",
"lemoncurry",
Expand Down
18 changes: 18 additions & 0 deletions exercises/practice/forth/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ description = "addition -> errors if there is nothing on the stack"
[06efb9a4-817a-435e-b509-06166993c1b8]
description = "addition -> errors if there is only one value on the stack"

[1e07a098-c5fa-4c66-97b2-3c81205dbc2f]
description = "addition -> more than two values on the stack"

[09687c99-7bbc-44af-8526-e402f997ccbf]
description = "subtraction -> can subtract two numbers"

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

[2c8cc5ed-da97-4cb1-8b98-fa7b526644f4]
description = "subtraction -> more than two values on the stack"

[5df0ceb5-922e-401f-974d-8287427dbf21]
description = "multiplication -> can multiply two numbers"

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

[5cd085b5-deb1-43cc-9c17-6b1c38bc9970]
description = "multiplication -> more than two values on the stack"

[e74c2204-b057-4cff-9aa9-31c7c97a93f5]
description = "division -> can divide two numbers"

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

[f224f3e0-b6b6-4864-81de-9769ecefa03f]
description = "division -> more than two values on the stack"

[ee28d729-6692-4a30-b9be-0d830c52a68c]
description = "combined arithmetic -> addition and subtraction"

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

[f749b540-53aa-458e-87ec-a70797eddbcb]
description = "combined arithmetic -> multiplication and addition"

[c8e5a4c2-f9bf-4805-9a35-3c3314e4989a]
description = "combined arithmetic -> addition and multiplication"

[c5758235-6eef-4bf6-ab62-c878e50b9957]
description = "dup -> copies a value on the stack"

Expand Down
40 changes: 40 additions & 0 deletions exercises/practice/forth/src/test/java/ForthEvaluatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public void testErrorIfAdditionAttemptedWithOneNumberOnTheStack() {
.withMessage("Addition requires that the stack contain at least 2 values");
}

@Disabled("Remove to run test")
@Test
public void testAdditionForMoreThanTwoValuesOnTheStack() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 +")))
.containsExactly(1, 5);
}

@Disabled("Remove to run test")
@Test
public void testTwoNumbersCanBeSubtracted() {
Expand All @@ -72,6 +79,13 @@ public void testErrorIfSubtractionAttemptedWithOneNumberOnTheStack() {
.withMessage("Subtraction requires that the stack contain at least 2 values");
}

@Disabled("Remove to run test")
@Test
public void testSubtractionForMoreThanTwoValuesOnTheStack() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 -")))
.containsExactly(1, 9);
}

@Disabled("Remove to run test")
@Test
public void testTwoNumbersCanBeMultiplied() {
Expand All @@ -94,6 +108,13 @@ public void testErrorIfMultiplicationAttemptedWithOneNumberOnTheStack() {
.withMessage("Multiplication requires that the stack contain at least 2 values");
}

@Disabled("Remove to run test")
@Test
public void testMultiplicationForMoreThanTwoValuesOnTheStack() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 2 3 *")))
.containsExactly(1, 6);
}

@Disabled("Remove to run test")
@Test
public void testTwoNumbersCanBeDivided() {
Expand Down Expand Up @@ -130,6 +151,13 @@ public void testErrorIfDivisionAttemptedWithOneNumberOnTheStack() {
.withMessage("Division requires that the stack contain at least 2 values");
}

@Disabled("Remove to run test")
@Test
public void testDivisionForMoreThanTwoValuesOnTheStack() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 12 3 /")))
.containsExactly(1, 4);
}

@Disabled("Remove to run test")
@Test
public void testCombinedAdditionAndSubtraction() {
Expand All @@ -142,6 +170,18 @@ public void testCombinedMultiplicationAndDivision() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("2 4 * 3 /"))).containsExactly(2);
}

@Disabled("Remove to run test")
@Test
public void testCombinedMultiplicationAndAddition() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 * +"))).containsExactly(13);
}

@Disabled("Remove to run test")
@Test
public void testCombinedAdditionAndMultiplication() {
assertThat(forthEvaluator.evaluateProgram(Collections.singletonList("1 3 4 + *"))).containsExactly(7);
}

@Disabled("Remove to run test")
@Test
public void testDupCopiesAValueOnTheStack() {
Expand Down