Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wordy: test that various syntax errors are in fact syntax errors #1383

Merged
merged 1 commit into from
Nov 9, 2018
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
42 changes: 41 additions & 1 deletion exercises/wordy/canonical-data.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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?"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's ignore the fact that in some languages, 1 + + 2 is a valid expression that evaluates to 3. The reason for the validity is that the second + sign is a unary plus. We are probably assuming in these word problems that the plus refers only to the binary operation.

},
"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"}
}
]
}
8 changes: 8 additions & 0 deletions exercises/wordy/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if this PR is rejected, I'd suggest adding these lines in any case!

* Word problems with invalid syntax ("What is 1 plus plus 2?")

## Bonus — Exponentials

If you'd like, handle exponentials.
Expand Down