Updtated tests for Forth from problem specs. (#3814)

This commit is contained in:
BethanyG
2024-11-04 16:09:36 -08:00
committed by GitHub
parent d7a8e5b8d1
commit dcc052c730
2 changed files with 37 additions and 1 deletions

View File

@@ -24,6 +24,9 @@ description = "addition -> errors if there is nothing on the stack"
[06efb9a4-817a-435e-b509-06166993c1b8] [06efb9a4-817a-435e-b509-06166993c1b8]
description = "addition -> errors if there is only one value on the stack" 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] [09687c99-7bbc-44af-8526-e402f997ccbf]
description = "subtraction -> can subtract two numbers" description = "subtraction -> can subtract two numbers"
@@ -33,6 +36,9 @@ description = "subtraction -> errors if there is nothing on the stack"
[b3cee1b2-9159-418a-b00d-a1bb3765c23b] [b3cee1b2-9159-418a-b00d-a1bb3765c23b]
description = "subtraction -> errors if there is only one value on the stack" 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] [5df0ceb5-922e-401f-974d-8287427dbf21]
description = "multiplication -> can multiply two numbers" description = "multiplication -> can multiply two numbers"
@@ -42,6 +48,9 @@ description = "multiplication -> errors if there is nothing on the stack"
[8ba4b432-9f94-41e0-8fae-3b3712bd51b3] [8ba4b432-9f94-41e0-8fae-3b3712bd51b3]
description = "multiplication -> errors if there is only one value on the stack" 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] [e74c2204-b057-4cff-9aa9-31c7c97a93f5]
description = "division -> can divide two numbers" description = "division -> can divide two numbers"
@@ -57,12 +66,21 @@ description = "division -> errors if there is nothing on the stack"
[d5547f43-c2ff-4d5c-9cb0-2a4f6684c20d] [d5547f43-c2ff-4d5c-9cb0-2a4f6684c20d]
description = "division -> errors if there is only one value on the stack" 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] [ee28d729-6692-4a30-b9be-0d830c52a68c]
description = "combined arithmetic -> addition and subtraction" description = "combined arithmetic -> addition and subtraction"
[40b197da-fa4b-4aca-a50b-f000d19422c1] [40b197da-fa4b-4aca-a50b-f000d19422c1]
description = "combined arithmetic -> multiplication and division" 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] [c5758235-6eef-4bf6-ab62-c878e50b9957]
description = "dup -> copies a value on the stack" description = "dup -> copies a value on the stack"

View File

@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from: # These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/forth/canonical-data.json # https://github.com/exercism/problem-specifications/tree/main/exercises/forth/canonical-data.json
# File last updated on 2023-07-19 # File last updated on 2024-11-04
import unittest import unittest
@@ -36,6 +36,9 @@ class ForthTest(unittest.TestCase):
str(err.exception.args[0]), "Insufficient number of items in stack" str(err.exception.args[0]), "Insufficient number of items in stack"
) )
def test_addition_more_than_two_values_on_the_stack(self):
self.assertEqual(evaluate(["1 2 3 +"]), [1, 5])
def test_subtraction_can_subtract_two_numbers(self): def test_subtraction_can_subtract_two_numbers(self):
self.assertEqual(evaluate(["3 4 -"]), [-1]) self.assertEqual(evaluate(["3 4 -"]), [-1])
@@ -55,6 +58,9 @@ class ForthTest(unittest.TestCase):
str(err.exception.args[0]), "Insufficient number of items in stack" str(err.exception.args[0]), "Insufficient number of items in stack"
) )
def test_subtraction_more_than_two_values_on_the_stack(self):
self.assertEqual(evaluate(["1 12 3 -"]), [1, 9])
def test_multiplication_can_multiply_two_numbers(self): def test_multiplication_can_multiply_two_numbers(self):
self.assertEqual(evaluate(["2 4 *"]), [8]) self.assertEqual(evaluate(["2 4 *"]), [8])
@@ -74,6 +80,9 @@ class ForthTest(unittest.TestCase):
str(err.exception.args[0]), "Insufficient number of items in stack" str(err.exception.args[0]), "Insufficient number of items in stack"
) )
def test_multiplication_more_than_two_values_on_the_stack(self):
self.assertEqual(evaluate(["1 2 3 *"]), [1, 6])
def test_division_can_divide_two_numbers(self): def test_division_can_divide_two_numbers(self):
self.assertEqual(evaluate(["12 3 /"]), [4]) self.assertEqual(evaluate(["12 3 /"]), [4])
@@ -103,12 +112,21 @@ class ForthTest(unittest.TestCase):
str(err.exception.args[0]), "Insufficient number of items in stack" str(err.exception.args[0]), "Insufficient number of items in stack"
) )
def test_division_more_than_two_values_on_the_stack(self):
self.assertEqual(evaluate(["1 12 3 /"]), [1, 4])
def test_combined_arithmetic_addition_and_subtraction(self): def test_combined_arithmetic_addition_and_subtraction(self):
self.assertEqual(evaluate(["1 2 + 4 -"]), [-1]) self.assertEqual(evaluate(["1 2 + 4 -"]), [-1])
def test_combined_arithmetic_multiplication_and_division(self): def test_combined_arithmetic_multiplication_and_division(self):
self.assertEqual(evaluate(["2 4 * 3 /"]), [2]) self.assertEqual(evaluate(["2 4 * 3 /"]), [2])
def test_combined_arithmetic_multiplication_and_addition(self):
self.assertEqual(evaluate(["1 3 4 * +"]), [13])
def test_combined_arithmetic_addition_and_multiplication(self):
self.assertEqual(evaluate(["1 3 4 + *"]), [7])
def test_dup_copies_a_value_on_the_stack(self): def test_dup_copies_a_value_on_the_stack(self):
self.assertEqual(evaluate(["1 dup"]), [1, 1]) self.assertEqual(evaluate(["1 dup"]), [1, 1])