Skip to content

all-your-base: Be explicit about error cases #1000

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

Merged
merged 1 commit into from
Nov 11, 2017
Merged
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
25 changes: 10 additions & 15 deletions exercises/all-your-base/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exercise": "all-your-base",
"version": "1.2.0",
"version": "2.0.0",
"comments": [
"This canonical data makes the following choices:",
"1. Zero is always represented in outputs as [0] instead of [].",
Expand All @@ -10,11 +10,6 @@
"",
"Tracks that wish to make different decisions for these choices may translate appropriately.",
"",
"It's up to each track do decide:",
"How should invalid input be handled?",
"",
"All the undefined cases are marked as null.",
"",
"All your numeric-base are belong to [2..]. :)"
],
"cases": [
Expand Down Expand Up @@ -120,71 +115,71 @@
"input_base": 1,
"input_digits": [],
"output_base": 10,
"expected": null
"expected": {"error": "input base must be >= 2"}
},
{
"description": "first base is zero",
"property": "rebase",
"input_base": 0,
"input_digits": [],
"output_base": 10,
"expected": null
"expected": {"error": "input base must be >= 2"}
},
{
"description": "first base is negative",
"property": "rebase",
"input_base": -2,
"input_digits": [1],
"output_base": 10,
"expected": null
"expected": {"error": "input base must be >= 2"}
},
{
"description": "negative digit",
"property": "rebase",
"input_base": 2,
"input_digits": [1, -1, 1, 0, 1, 0],
"output_base": 10,
"expected": null
"expected": {"error": "all digits must satisfy 0 <= d < input base"}
Copy link
Contributor

Choose a reason for hiding this comment

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

pedantic_mode: Is -1 really a digit?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see why one would ask this question, and it is true that in all bases allowed in this problem, digits can be considered to be unsigned values.

So thus, I present for academic curiosity https://en.wikipedia.org/wiki/Balanced_ternary, in which there is the possibility of negative digits.

},
{
"description": "invalid positive digit",
"property": "rebase",
"input_base": 2,
"input_digits": [1, 2, 1, 0, 1, 0],
"output_base": 10,
"expected": null
"expected": {"error": "all digits must satisfy 0 <= d < input base"}
},
{
"description": "second base is one",
"property": "rebase",
"input_base": 2,
"input_digits": [1, 0, 1, 0, 1, 0],
"output_base": 1,
"expected": null
"expected": {"error": "output base must be >= 2"}
},
{
"description": "second base is zero",
"property": "rebase",
"input_base": 10,
"input_digits": [7],
"output_base": 0,
"expected": null
"expected": {"error": "output base must be >= 2"}
},
{
"description": "second base is negative",
"property": "rebase",
"input_base": 2,
"input_digits": [1],
"output_base": -7,
"expected": null
"expected": {"error": "output base must be >= 2"}
},
{
"description": "both bases are negative",
"property": "rebase",
"input_base": -2,
"input_digits": [1],
"output_base": -7,
"expected": null
"expected": {"error": "input base must be >= 2"}
}
]
}