From 8eb887143a0ee0e5fdb7bc98405a1a5f7194b32f Mon Sep 17 00:00:00 2001 From: rbasso Date: Fri, 10 Mar 2017 21:04:21 +0900 Subject: [PATCH 1/2] forth: Make canonical-data.json compliant --- exercises/forth/canonical-data.json | 78 ++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/exercises/forth/canonical-data.json b/exercises/forth/canonical-data.json index 7a0037aeb3..1743183bcf 100644 --- a/exercises/forth/canonical-data.json +++ b/exercises/forth/canonical-data.json @@ -1,18 +1,24 @@ { - "#": [ + "exercise": "forth", + "version": "1.0.0", + "comments": [ "The cases are split into multiple sections, all with the same structure.", "In all cases, the `expected` key is the resulting stack", "after executing the Forth program contained in the `input` key." ], - "parsing and numbers": { + "cases": [ + { + "description": "parsing and numbers", "cases": [ { "description": "empty input results in empty stack", + "property": "evaluate", "input": [], "expected": [] }, { "description": "numbers just get pushed onto the stack", + "property": "evaluate", "input": [ "1 2 3 4 5" ], @@ -20,6 +26,7 @@ }, { "description": "all non-word characters are separators", + "property": "evaluate", "input": [ "1\u00002\u00133\n4\r5 6\t7" ], @@ -27,10 +34,12 @@ } ] }, - "addition": { + { + "description": "addition", "cases": [ { "description": "can add two numbers", + "property": "evaluate", "input": [ "1 2 +" ], @@ -38,6 +47,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "+" ], @@ -45,6 +55,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 +" ], @@ -52,10 +63,12 @@ } ] }, - "subtraction": { + { + "description": "subtraction", "cases": [ { "description": "can subtract two numbers", + "property": "evaluate", "input": [ "3 4 -" ], @@ -63,6 +76,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "-" ], @@ -70,6 +84,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 -" ], @@ -77,10 +92,12 @@ } ] }, - "multiplication": { + { + "description": "multiplication", "cases": [ { "description": "can multiply two numbers", + "property": "evaluate", "input": [ "2 4 *" ], @@ -88,6 +105,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "*" ], @@ -95,6 +113,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 *" ], @@ -102,10 +121,12 @@ } ] }, - "division": { + { + "description": "division", "cases": [ { "description": "can divide two numbers", + "property": "evaluate", "input": [ "12 3 /" ], @@ -113,6 +134,7 @@ }, { "description": "performs integer division", + "property": "evaluate", "input": [ "8 3 /" ], @@ -120,6 +142,7 @@ }, { "description": "errors if dividing by zero", + "property": "evaluate", "input": [ "4 0 /" ], @@ -127,6 +150,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "/" ], @@ -134,6 +158,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 /" ], @@ -141,10 +166,12 @@ } ] }, - "combined arithmetic": { + { + "description": "combined arithmetic", "cases": [ { "description": "addition and subtraction", + "property": "evaluate", "input": [ "1 2 + 4 -" ], @@ -152,6 +179,7 @@ }, { "description": "multiplication and division", + "property": "evaluate", "input": [ "2 4 * 3 /" ], @@ -159,10 +187,12 @@ } ] }, - "dup": { + { + "description": "dup", "cases": [ { "description": "copies the top value on the stack", + "property": "evaluate", "input": [ "1 DUP" ], @@ -170,6 +200,7 @@ }, { "description": "is case-insensitive", + "property": "evaluate", "input": [ "1 2 Dup" ], @@ -177,6 +208,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "dup" ], @@ -184,10 +216,12 @@ } ] }, - "drop": { + { + "description": "drop", "cases": [ { "description": "removes the top value on the stack if it is the only one", + "property": "evaluate", "input": [ "1 drop" ], @@ -195,6 +229,7 @@ }, { "description": "removes the top value on the stack if it is not the only one", + "property": "evaluate", "input": [ "1 2 drop" ], @@ -202,6 +237,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "drop" ], @@ -209,10 +245,12 @@ } ] }, - "swap": { + { + "description": "swap", "cases": [ { "description": "swaps the top two values on the stack if they are the only ones", + "property": "evaluate", "input": [ "1 2 swap" ], @@ -220,6 +258,7 @@ }, { "description": "swaps the top two values on the stack if they are not the only ones", + "property": "evaluate", "input": [ "1 2 3 swap" ], @@ -227,6 +266,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "swap" ], @@ -234,6 +274,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 swap" ], @@ -241,10 +282,12 @@ } ] }, - "over": { + { + "description": "over", "cases": [ { "description": "copies the second element if there are only two", + "property": "evaluate", "input": [ "1 2 over" ], @@ -252,6 +295,7 @@ }, { "description": "copies the second element if there are more than two", + "property": "evaluate", "input": [ "1 2 3 over" ], @@ -259,6 +303,7 @@ }, { "description": "errors if there is nothing on the stack", + "property": "evaluate", "input": [ "over" ], @@ -266,6 +311,7 @@ }, { "description": "errors if there is only one value on the stack", + "property": "evaluate", "input": [ "1 over" ], @@ -273,10 +319,12 @@ } ] }, - "user-defined words": { + { + "description": "user-defined words", "cases": [ { "description": "can consist of built-in words", + "property": "evaluate", "input": [ ": dup-twice dup dup ;", "1 dup-twice" @@ -285,6 +333,7 @@ }, { "description": "execute in the right order", + "property": "evaluate", "input": [ ": countup 1 2 3 ;", "countup" @@ -293,6 +342,7 @@ }, { "description": "can override other user-defined words", + "property": "evaluate", "input": [ ": foo dup ;", ": foo dup dup ;", @@ -302,6 +352,7 @@ }, { "description": "can override built-in words", + "property": "evaluate", "input": [ ": swap dup ;", "1 swap" @@ -310,6 +361,7 @@ }, { "description": "cannot redefine numbers", + "property": "evaluate", "input": [ ": 1 2 ;" ], @@ -317,6 +369,7 @@ }, { "description": "errors if executing a non-existent word", + "property": "evaluate", "input": [ "foo" ], @@ -324,4 +377,5 @@ } ] } + ] } From 0d6f5b78ba8b588b6113f8539e6f311e337d7018 Mon Sep 17 00:00:00 2001 From: rbasso Date: Sat, 11 Mar 2017 17:35:25 +0900 Subject: [PATCH 2/2] forth: Fix canonical-data.json formatting --- exercises/forth/canonical-data.json | 672 +++++++++++++--------------- 1 file changed, 302 insertions(+), 370 deletions(-) diff --git a/exercises/forth/canonical-data.json b/exercises/forth/canonical-data.json index 1743183bcf..f3a5f380a6 100644 --- a/exercises/forth/canonical-data.json +++ b/exercises/forth/canonical-data.json @@ -7,375 +7,307 @@ "after executing the Forth program contained in the `input` key." ], "cases": [ - { - "description": "parsing and numbers", - "cases": [ - { - "description": "empty input results in empty stack", - "property": "evaluate", - "input": [], - "expected": [] - }, - { - "description": "numbers just get pushed onto the stack", - "property": "evaluate", - "input": [ - "1 2 3 4 5" - ], - "expected": [1, 2, 3, 4, 5] - }, - { - "description": "all non-word characters are separators", - "property": "evaluate", - "input": [ - "1\u00002\u00133\n4\r5 6\t7" - ], - "expected": [1, 2, 3, 4, 5, 6, 7] - } - ] - }, - { - "description": "addition", - "cases": [ - { - "description": "can add two numbers", - "property": "evaluate", - "input": [ - "1 2 +" - ], - "expected": [3] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "+" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 +" - ], - "expected": null - } - ] - }, - { - "description": "subtraction", - "cases": [ - { - "description": "can subtract two numbers", - "property": "evaluate", - "input": [ - "3 4 -" - ], - "expected": [-1] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "-" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 -" - ], - "expected": null - } - ] - }, - { - "description": "multiplication", - "cases": [ - { - "description": "can multiply two numbers", - "property": "evaluate", - "input": [ - "2 4 *" - ], - "expected": [8] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "*" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 *" - ], - "expected": null - } - ] - }, - { - "description": "division", - "cases": [ - { - "description": "can divide two numbers", - "property": "evaluate", - "input": [ - "12 3 /" - ], - "expected": [4] - }, - { - "description": "performs integer division", - "property": "evaluate", - "input": [ - "8 3 /" - ], - "expected": [2] - }, - { - "description": "errors if dividing by zero", - "property": "evaluate", - "input": [ - "4 0 /" - ], - "expected": null - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "/" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 /" - ], - "expected": null - } - ] - }, - { - "description": "combined arithmetic", - "cases": [ - { - "description": "addition and subtraction", - "property": "evaluate", - "input": [ - "1 2 + 4 -" - ], - "expected": [-1] - }, - { - "description": "multiplication and division", - "property": "evaluate", - "input": [ - "2 4 * 3 /" - ], - "expected": [2] - } - ] - }, - { - "description": "dup", - "cases": [ - { - "description": "copies the top value on the stack", - "property": "evaluate", - "input": [ - "1 DUP" - ], - "expected": [1, 1] - }, - { - "description": "is case-insensitive", - "property": "evaluate", - "input": [ - "1 2 Dup" - ], - "expected": [1, 2, 2] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "dup" - ], - "expected": null - } - ] - }, - { - "description": "drop", - "cases": [ - { - "description": "removes the top value on the stack if it is the only one", - "property": "evaluate", - "input": [ - "1 drop" - ], - "expected": [] - }, - { - "description": "removes the top value on the stack if it is not the only one", - "property": "evaluate", - "input": [ - "1 2 drop" - ], - "expected": [1] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "drop" - ], - "expected": null - } - ] - }, - { - "description": "swap", - "cases": [ - { - "description": "swaps the top two values on the stack if they are the only ones", - "property": "evaluate", - "input": [ - "1 2 swap" - ], - "expected": [2, 1] - }, - { - "description": "swaps the top two values on the stack if they are not the only ones", - "property": "evaluate", - "input": [ - "1 2 3 swap" - ], - "expected": [1, 3, 2] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "swap" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 swap" - ], - "expected": null - } - ] - }, - { - "description": "over", - "cases": [ - { - "description": "copies the second element if there are only two", - "property": "evaluate", - "input": [ - "1 2 over" - ], - "expected": [1, 2, 1] - }, - { - "description": "copies the second element if there are more than two", - "property": "evaluate", - "input": [ - "1 2 3 over" - ], - "expected": [1, 2, 3, 2] - }, - { - "description": "errors if there is nothing on the stack", - "property": "evaluate", - "input": [ - "over" - ], - "expected": null - }, - { - "description": "errors if there is only one value on the stack", - "property": "evaluate", - "input": [ - "1 over" - ], - "expected": null - } - ] - }, - { - "description": "user-defined words", - "cases": [ - { - "description": "can consist of built-in words", - "property": "evaluate", - "input": [ - ": dup-twice dup dup ;", - "1 dup-twice" - ], - "expected": [1, 1, 1] - }, - { - "description": "execute in the right order", - "property": "evaluate", - "input": [ - ": countup 1 2 3 ;", - "countup" - ], - "expected": [1, 2, 3] - }, - { - "description": "can override other user-defined words", - "property": "evaluate", - "input": [ - ": foo dup ;", - ": foo dup dup ;", - "1 foo" - ], - "expected": [1, 1, 1] - }, - { - "description": "can override built-in words", - "property": "evaluate", - "input": [ - ": swap dup ;", - "1 swap" - ], - "expected": [1, 1] - }, - { - "description": "cannot redefine numbers", - "property": "evaluate", - "input": [ - ": 1 2 ;" - ], - "expected": null - }, - { - "description": "errors if executing a non-existent word", - "property": "evaluate", - "input": [ - "foo" - ], - "expected": null - } - ] - } + { + "description": "parsing and numbers", + "cases": [ + { + "description": "empty input results in empty stack", + "property": "evaluate", + "input": [], + "expected": [] + }, + { + "description": "numbers just get pushed onto the stack", + "property": "evaluate", + "input": ["1 2 3 4 5"], + "expected": [1, 2, 3, 4, 5] + }, + { + "description": "all non-word characters are separators", + "property": "evaluate", + "input": ["1\u00002\u00133\n4\r5 6\t7"], + "expected": [1, 2, 3, 4, 5, 6, 7] + } + ] + }, + { + "description": "addition", + "cases": [ + { + "description": "can add two numbers", + "property": "evaluate", + "input": ["1 2 +"], + "expected": [3] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["+"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 +"], + "expected": null + } + ] + }, + { + "description": "subtraction", + "cases": [ + { + "description": "can subtract two numbers", + "property": "evaluate", + "input": ["3 4 -"], + "expected": [-1] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["-"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 -"], + "expected": null + } + ] + }, + { + "description": "multiplication", + "cases": [ + { + "description": "can multiply two numbers", + "property": "evaluate", + "input": ["2 4 *"], + "expected": [8] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["*"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 *"], + "expected": null + } + ] + }, + { + "description": "division", + "cases": [ + { + "description": "can divide two numbers", + "property": "evaluate", + "input": ["12 3 /"], + "expected": [4] + }, + { + "description": "performs integer division", + "property": "evaluate", + "input": ["8 3 /"], + "expected": [2] + }, + { + "description": "errors if dividing by zero", + "property": "evaluate", + "input": ["4 0 /"], + "expected": null + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["/"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 /"], + "expected": null + } + ] + }, + { + "description": "combined arithmetic", + "cases": [ + { + "description": "addition and subtraction", + "property": "evaluate", + "input": ["1 2 + 4 -"], + "expected": [-1] + }, + { + "description": "multiplication and division", + "property": "evaluate", + "input": ["2 4 * 3 /"], + "expected": [2] + } + ] + }, + { + "description": "dup", + "cases": [ + { + "description": "copies the top value on the stack", + "property": "evaluate", + "input": ["1 DUP"], + "expected": [1, 1] + }, + { + "description": "is case-insensitive", + "property": "evaluate", + "input": ["1 2 Dup"], + "expected": [1, 2, 2] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["dup"], + "expected": null + } + ] + }, + { + "description": "drop", + "cases": [ + { + "description": "removes the top value on the stack if it is the only one", + "property": "evaluate", + "input": ["1 drop"], + "expected": [] + }, + { + "description": "removes the top value on the stack if it is not the only one", + "property": "evaluate", + "input": ["1 2 drop"], + "expected": [1] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["drop"], + "expected": null + } + ] + }, + { + "description": "swap", + "cases": [ + { + "description": "swaps the top two values on the stack if they are the only ones", + "property": "evaluate", + "input": ["1 2 swap"], + "expected": [2, 1] + }, + { + "description": "swaps the top two values on the stack if they are not the only ones", + "property": "evaluate", + "input": ["1 2 3 swap"], + "expected": [1, 3, 2] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["swap"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 swap"], + "expected": null + } + ] + }, + { + "description": "over", + "cases": [ + { + "description": "copies the second element if there are only two", + "property": "evaluate", + "input": ["1 2 over"], + "expected": [1, 2, 1] + }, + { + "description": "copies the second element if there are more than two", + "property": "evaluate", + "input": ["1 2 3 over"], + "expected": [1, 2, 3, 2] + }, + { + "description": "errors if there is nothing on the stack", + "property": "evaluate", + "input": ["over"], + "expected": null + }, + { + "description": "errors if there is only one value on the stack", + "property": "evaluate", + "input": ["1 over"], + "expected": null + } + ] + }, + { + "description": "user-defined words", + "cases": [ + { + "description": "can consist of built-in words", + "property": "evaluate", + "input": [ + ": dup-twice dup dup ;", + "1 dup-twice" + ], + "expected": [1, 1, 1] + }, + { + "description": "execute in the right order", + "property": "evaluate", + "input": [ + ": countup 1 2 3 ;", + "countup" + ], + "expected": [1, 2, 3] + }, + { + "description": "can override other user-defined words", + "property": "evaluate", + "input": [ + ": foo dup ;", + ": foo dup dup ;", + "1 foo" + ], + "expected": [1, 1, 1] + }, + { + "description": "can override built-in words", + "property": "evaluate", + "input": [ + ": swap dup ;", + "1 swap" + ], + "expected": [1, 1] + }, + { + "description": "cannot redefine numbers", + "property": "evaluate", + "input": [": 1 2 ;"], + "expected": null + }, + { + "description": "errors if executing a non-existent word", + "property": "evaluate", + "input": ["foo"], + "expected": null + } + ] + } ] }