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

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

merged 1 commit into from
Nov 9, 2018

Conversation

petertseng
Copy link
Member

@petertseng petertseng commented Nov 4, 2018

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.

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.

Intentional merge conflict for the same reason as #1382

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!

"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.

Copy link
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

This seems like a good idea.

@@ -134,6 +134,38 @@
"question": "Who is the President of the United States?"
},
"expected": false
Copy link
Member

Choose a reason for hiding this comment

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

I think all instances of "expected": false should be converted to syntax errors in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

will happen when rebasing on top of #1334

@petertseng
Copy link
Member Author

I'm going to add another case that I think will be useful to test: "What is 1 plus?"

@petertseng
Copy link
Member Author

With regard to #902 - one very good argument against testing invalid inputs there was that we can imagine there is an additional layer above the problem that takes on the job of filtering out any invalid inputs.

For problems like nucleotide-count this makes sense because this filtering can be done sort of independently of the meat of the problem.

For a problem like wordy, it seems to me that something that filters for invalid inputs would probably need to parse the input, which is part of the meat of the problem here. Thus, to test these syntax errors is consistent with the ideas of #902.

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]: exercism/rust#704 (comment)

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.
@petertseng
Copy link
Member Author

Since I have an approval, if no further comments are forthcoming, one should expect me to merge this when 120 hours have passed since the PR was submitted.

Copy link
Member

@rpottsoh rpottsoh left a comment

Choose a reason for hiding this comment

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

@petertseng at first these changes bothered me. But I have had time to consider them and I think they are spot on. What you have done seems to me to dovetail nicely with the conversation that took place at #1346.

@petertseng petertseng merged commit 86bef22 into exercism:master Nov 9, 2018
@petertseng petertseng deleted the wordy-order branch November 9, 2018 23:09
petertseng added a commit to exercism/haskell that referenced this pull request Nov 23, 2018
…#779)

In keeping with [1.3.0][], we want to test that this fails in an
expected way rather than an unexpected way.

[1.3.0]: exercism/problem-specifications#1383

Specifically for Haskell, we want to make sure that this results in
`None` rather than accessing an out-of-bounds index due to always
assuming that the inputs will have at least three space-separated
elements (of the form "What is X...?").

exercism/problem-specifications#1401
petertseng added a commit to exercism/rust that referenced this pull request Nov 24, 2018
…764)

In keeping with [1.3.0][], we want to test that this fails in an
expected way rather than an unexpected way.

[1.3.0]: exercism/problem-specifications#1383

Specifically for Rust, we want to make sure that this results in `None`
rather than accessing an out-of-bounds index due to always assuming that
the inputs will have at least three space-separated elements (of the
form "What is X...?").

exercism/problem-specifications#1401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants