From e5cb2554fe8900fc36b033876db25da1c13fb5d7 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Tue, 8 Oct 2024 18:02:13 -0400 Subject: [PATCH] sync tests forth --- exercises/practice/forth/.meta/tests.toml | 18 +++ exercises/practice/forth/forth.test | 127 ++++++++++++++-------- 2 files changed, 97 insertions(+), 48 deletions(-) diff --git a/exercises/practice/forth/.meta/tests.toml b/exercises/practice/forth/.meta/tests.toml index c9c1d637..d1e146a1 100644 --- a/exercises/practice/forth/.meta/tests.toml +++ b/exercises/practice/forth/.meta/tests.toml @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/exercises/practice/forth/forth.test b/exercises/practice/forth/forth.test index cc0e7e60..94d0946e 100644 --- a/exercises/practice/forth/forth.test +++ b/exercises/practice/forth/forth.test @@ -9,242 +9,273 @@ source testHelpers.tcl ############################################################ source "forth.tcl" -test forth-1 "numbers just get pushed onto the stack" -body { +test forth-1 "parsing and numbers: numbers just get pushed onto the stack" -body { evalForth "1 2 3 4 5" } -returnCodes ok -result {1 2 3 4 5} skip forth-2 -test forth-2 "pushes negative numbers onto the stack" -body { +test forth-2 "parsing and numbers: pushes negative numbers onto the stack" -body { evalForth "-1 -2 -3 -4 -5" } -returnCodes ok -result {-1 -2 -3 -4 -5} skip forth-3 -test forth-3 "can add two numbers" -body { +test forth-3 "addition: can add two numbers" -body { evalForth "1 2 +" } -returnCodes ok -result {3} skip forth-4 -test forth-4 "errors if there is nothing on the stack" -body { +test forth-4 "addition: errors if there is nothing on the stack" -body { evalForth "+" } -returnCodes error -result "empty stack" skip forth-5 -test forth-5 "errors if there is only one value on the stack" -body { +test forth-5 "addition: errors if there is only one value on the stack" -body { evalForth "1 +" } -returnCodes error -result "only one value on the stack" +skip forth-5a +test forth-5a "addition: more than one value on the stack" -body { + evalForth "1 2 3 +" +} -returnCodes ok -result {1 5} + skip forth-6 -test forth-6 "can subtract two numbers" -body { +test forth-6 "subtraction: can subtract two numbers" -body { evalForth "3 4 -" } -returnCodes ok -result {-1} skip forth-7 -test forth-7 "errors if there is nothing on the stack" -body { +test forth-7 "subtraction: errors if there is nothing on the stack" -body { evalForth "-" } -returnCodes error -result "empty stack" skip forth-8 -test forth-8 "errors if there is only one value on the stack" -body { +test forth-8 "subtraction: errors if there is only one value on the stack" -body { evalForth "1 -" } -returnCodes error -result "only one value on the stack" +skip forth-8a +test forth-8a "subtraction: more than one value on the stack" -body { + evalForth "1 12 3 -" +} -returnCodes ok -result {1 9} + skip forth-9 -test forth-9 "can multiply two numbers" -body { +test forth-9 "multiplication: can multiply two numbers" -body { evalForth "2 4 *" } -returnCodes ok -result {8} skip forth-10 -test forth-10 "errors if there is nothing on the stack" -body { +test forth-10 "multiplication: errors if there is nothing on the stack" -body { evalForth "*" } -returnCodes error -result "empty stack" skip forth-11 -test forth-11 "errors if there is only one value on the stack" -body { +test forth-11 "multiplication: errors if there is only one value on the stack" -body { evalForth "1 *" } -returnCodes error -result "only one value on the stack" +skip forth-11a +test forth-11a "multiplication: more than one value on the stack" -body { + evalForth "1 2 3 *" +} -returnCodes ok -result {1 6} + skip forth-12 -test forth-12 "can divide two numbers" -body { +test forth-12 "division: can divide two numbers" -body { evalForth "12 3 /" } -returnCodes ok -result {4} skip forth-13 -test forth-13 "performs integer division" -body { +test forth-13 "division: performs integer division" -body { evalForth "8 3 /" } -returnCodes ok -result {2} skip forth-14 -test forth-14 "errors if dividing by zero" -body { +test forth-14 "division: errors if dividing by zero" -body { evalForth "4 0 /" } -returnCodes error -result "divide by zero" skip forth-15 -test forth-15 "errors if there is nothing on the stack" -body { +test forth-15 "division: errors if there is nothing on the stack" -body { evalForth "/" } -returnCodes error -result "empty stack" skip forth-16 -test forth-16 "errors if there is only one value on the stack" -body { +test forth-16 "division: errors if there is only one value on the stack" -body { evalForth "1 /" } -returnCodes error -result "only one value on the stack" +skip forth-16a +test forth-16a "division: more than one value on the stack" -body { + evalForth "1 12 3 /" +} -returnCodes ok -result {1 4} + + skip forth-17 -test forth-17 "addition and subtraction" -body { +test forth-17 "combined arithmetic: addition and subtraction" -body { evalForth "1 2 + 4 -" } -returnCodes ok -result {-1} skip forth-18 -test forth-18 "multiplication and division" -body { +test forth-18 "combined arithmetic: multiplication and division" -body { evalForth "2 4 * 3 /" } -returnCodes ok -result {2} +skip forth-18a +test forth-18a "combined arithmetic: multiplication and addition" -body { + evalForth "1 3 4 * +" +} -returnCodes ok -result {13} + +skip forth-18b +test forth-18b "combined arithmetic: addition and multiplication" -body { + evalForth "1 3 4 + *" +} -returnCodes ok -result {7} + skip forth-19 -test forth-19 "copies a value on the stack" -body { +test forth-19 "dup: copies a value on the stack" -body { evalForth "1 dup" } -returnCodes ok -result {1 1} skip forth-20 -test forth-20 "copies the top value on the stack" -body { +test forth-20 "dup: copies the top value on the stack" -body { evalForth "1 2 dup" } -returnCodes ok -result {1 2 2} skip forth-21 -test forth-21 "errors if there is nothing on the stack" -body { +test forth-21 "dup: errors if there is nothing on the stack" -body { evalForth "dup" } -returnCodes error -result "empty stack" skip forth-22 -test forth-22 "removes the top value on the stack if it is the only one" -body { +test forth-22 "drop: removes the top value on the stack if it is the only one" -body { evalForth "1 drop" } -returnCodes ok -result {} skip forth-23 -test forth-23 "removes the top value on the stack if it is not the only one" -body { +test forth-23 "drop: removes the top value on the stack if it is not the only one" -body { evalForth "1 2 drop" } -returnCodes ok -result {1} skip forth-24 -test forth-24 "errors if there is nothing on the stack" -body { +test forth-24 "drop: errors if there is nothing on the stack" -body { evalForth "drop" } -returnCodes error -result "empty stack" skip forth-25 -test forth-25 "swaps the top two values on the stack if they are the only ones" -body { +test forth-25 "swap: swaps the top two values on the stack if they are the only ones" -body { evalForth "1 2 swap" } -returnCodes ok -result {2 1} skip forth-26 -test forth-26 "swaps the top two values on the stack if they are not the only ones" -body { +test forth-26 "swap: swaps the top two values on the stack if they are not the only ones" -body { evalForth "1 2 3 swap" } -returnCodes ok -result {1 3 2} skip forth-27 -test forth-27 "errors if there is nothing on the stack" -body { +test forth-27 "swap: errors if there is nothing on the stack" -body { evalForth "swap" } -returnCodes error -result "empty stack" skip forth-28 -test forth-28 "errors if there is only one value on the stack" -body { +test forth-28 "swap: errors if there is only one value on the stack" -body { evalForth "1 swap" } -returnCodes error -result "only one value on the stack" skip forth-29 -test forth-29 "copies the second element if there are only two" -body { +test forth-29 "over: copies the second element if there are only two" -body { evalForth "1 2 over" } -returnCodes ok -result {1 2 1} skip forth-30 -test forth-30 "copies the second element if there are more than two" -body { +test forth-30 "over: copies the second element if there are more than two" -body { evalForth "1 2 3 over" } -returnCodes ok -result {1 2 3 2} skip forth-31 -test forth-31 "errors if there is nothing on the stack" -body { +test forth-31 "over: errors if there is nothing on the stack" -body { evalForth "over" } -returnCodes error -result "empty stack" skip forth-32 -test forth-32 "errors if there is only one value on the stack" -body { +test forth-32 "over: errors if there is only one value on the stack" -body { evalForth "1 over" } -returnCodes error -result "only one value on the stack" skip forth-33 -test forth-33 "can consist of built-in words" -body { +test forth-33 "user-defined words: can consist of built-in words" -body { evalForth ": dup-twice dup dup ;\n1 dup-twice" } -returnCodes ok -result {1 1 1} skip forth-34 -test forth-34 "execute in the right order" -body { +test forth-34 "user-defined words: execute in the right order" -body { evalForth ": countup 1 2 3 ;\ncountup" } -returnCodes ok -result {1 2 3} skip forth-35 -test forth-35 "can override other user-defined words" -body { +test forth-35 "user-defined words: can override other user-defined words" -body { evalForth ": foo dup ;\n: foo dup dup ;\n1 foo" } -returnCodes ok -result {1 1 1} skip forth-36 -test forth-36 "can override built-in words" -body { +test forth-36 "user-defined words: can override built-in words" -body { evalForth ": swap dup ;\n1 swap" } -returnCodes ok -result {1 1} skip forth-37 -test forth-37 "can override built-in operators" -body { +test forth-37 "user-defined words: can override built-in operators" -body { evalForth ": + * ;\n3 4 +" } -returnCodes ok -result {12} skip forth-38 -test forth-38 "can use different words with the same name" -body { +test forth-38 "user-defined words: can use different words with the same name" -body { evalForth ": foo 5 ;\n: bar foo ;\n: foo 6 ;\nbar foo" } -returnCodes ok -result {5 6} skip forth-39 -test forth-39 "can define word that uses word with the same name" -body { +test forth-39 "user-defined words: can define word that uses word with the same name" -body { evalForth ": foo 10 ;\n: foo foo 1 + ;\nfoo" } -returnCodes ok -result {11} skip forth-40 -test forth-40 "cannot redefine non-negative numbers" -body { +test forth-40 "user-defined words: cannot redefine non-negative numbers" -body { evalForth ": 1 2 ;" } -returnCodes error -result "illegal operation" skip forth-41 -test forth-41 "cannot redefine negative numbers" -body { +test forth-41 "user-defined words: cannot redefine negative numbers" -body { evalForth ": -1 2 ;" } -returnCodes error -result "illegal operation" skip forth-42 -test forth-42 "errors if executing a non-existent word" -body { +test forth-42 "user-defined words: errors if executing a non-existent word" -body { evalForth "foo" } -returnCodes error -result "undefined operation" skip forth-43 -test forth-43 "DUP is case-insensitive" -body { +test forth-43 "case-insensitivity: DUP is case-insensitive" -body { evalForth "1 DUP Dup dup" } -returnCodes ok -result {1 1 1 1} skip forth-44 -test forth-44 "DROP is case-insensitive" -body { +test forth-44 "case-insensitivity: DROP is case-insensitive" -body { evalForth "1 2 3 4 DROP Drop drop" } -returnCodes ok -result {1} skip forth-45 -test forth-45 "SWAP is case-insensitive" -body { +test forth-45 "case-insensitivity: SWAP is case-insensitive" -body { evalForth "1 2 SWAP 3 Swap 4 swap" } -returnCodes ok -result {2 3 4 1} skip forth-46 -test forth-46 "OVER is case-insensitive" -body { +test forth-46 "case-insensitivity: OVER is case-insensitive" -body { evalForth "1 2 OVER Over over" } -returnCodes ok -result {1 2 1 2 1} skip forth-47 -test forth-47 "user-defined words are case-insensitive" -body { +test forth-47 "case-insensitivity: user-defined words are case-insensitive" -body { evalForth ": foo dup ;\n1 FOO Foo foo" } -returnCodes ok -result {1 1 1 1} skip forth-48 -test forth-48 "definitions are case-insensitive" -body { +test forth-48 "case-insensitivity: definitions are case-insensitive" -body { evalForth ": SWAP DUP Dup dup ;\n1 swap" } -returnCodes ok -result {1 1 1 1}