From 9868efbc77bc9f92674430f0c54b39006d26484e Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Sun, 4 Nov 2018 19:57:14 +0000 Subject: [PATCH] wordy: test that various syntax errors are in fact syntax errors By explicitly testing these we are making sure that the implementation fails in an appropriate way, rather than failing in an inappropriate way or erroneously giving an answer. For example, in languages using an optional for their answer, ensuring that [None is returned instead of panicking/aborting][1]. [1]: https://github.com/exercism/rust/pull/704#discussion_r230593072 This is beneficial because the problem is partially about building a parser (even if very rudimentary), and it's common for parsers to have to deal with errors like this. We may otherwise see some unfortunately fragile parsers. --- exercises/wordy/canonical-data.json | 42 ++++++++++++++++++++++++++++- exercises/wordy/description.md | 8 ++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/exercises/wordy/canonical-data.json b/exercises/wordy/canonical-data.json index ab7384c8d7..79b0f66049 100644 --- a/exercises/wordy/canonical-data.json +++ b/exercises/wordy/canonical-data.json @@ -1,6 +1,6 @@ { "exercise": "wordy", - "version": "1.2.0", + "version": "1.3.0", "comments": [ "The tests that expect an 'error' should be implemented to raise", "an error, or indicate a failure. Implement this in a way that", @@ -134,6 +134,46 @@ "question": "Who is the President of the United States?" }, "expected": {"error": "unknown operation"} + }, + { + "description": "reject incomplete problem", + "property": "answer", + "input": { + "question": "What is 1 plus?" + }, + "expected": {"error": "syntax error"} + }, + { + "description": "reject two operations in a row", + "property": "answer", + "input": { + "question": "What is 1 plus plus 2?" + }, + "expected": {"error": "syntax error"} + }, + { + "description": "reject two numbers in a row", + "property": "answer", + "input": { + "question": "What is 1 plus 2 1?" + }, + "expected": {"error": "syntax error"} + }, + { + "description": "reject postfix notation", + "property": "answer", + "input": { + "question": "What is 1 2 plus?" + }, + "expected": {"error": "syntax error"} + }, + { + "description": "reject prefix notation", + "property": "answer", + "input": { + "question": "What is plus 1 2?" + }, + "expected": {"error": "syntax error"} } ] } \ No newline at end of file diff --git a/exercises/wordy/description.md b/exercises/wordy/description.md index 50b9eac5d5..6e97f6f4a4 100644 --- a/exercises/wordy/description.md +++ b/exercises/wordy/description.md @@ -41,6 +41,14 @@ left-to-right, _ignoring the typical order of operations._ 15 (i.e. not 9) +## Iteration 4 — Errors + +The parser should reject: + +* Unsupported operations ("What is 52 cubed?") +* Non-math questions ("Who is the President of the United States") +* Word problems with invalid syntax ("What is 1 plus plus 2?") + ## Bonus — Exponentials If you'd like, handle exponentials.