-
-
Notifications
You must be signed in to change notification settings - Fork 554
list-ops: reimplement ambiguous tests #1746
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
Changes from all commits
f19d893
4aaec16
f0712e1
f4650f0
8e08681
b00f7aa
ac1e44f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,12 @@ | |
}, | ||
{ | ||
"description": "folds (reduces) the given list from the left with a function", | ||
"comments": [ | ||
"For function: acc is the accumulator and el is the current element. ", | ||
"The order of the arguments (ie. acc, el or el, acc) should match the ", | ||
"conventions common to the language of the track implementing this. ", | ||
"See https://github.com/exercism/problem-specifications/pull/1746#discussion_r548303995 for further advice." | ||
], | ||
"cases": [ | ||
{ | ||
"uuid": "613b20b7-1873-4070-a3a6-70ae5f50d7cc", | ||
|
@@ -184,18 +190,78 @@ | |
{ | ||
"uuid": "d2cf5644-aee1-4dfc-9b88-06896676fe27", | ||
"description": "direction dependent function applied to non-empty list", | ||
"comments": [ | ||
"Expects integer division (expects / to discard fractions). " | ||
], | ||
"property": "foldl", | ||
"input": { | ||
"list": [2, 5], | ||
"initial": 5, | ||
"function": "(x, y) -> x / y" | ||
}, | ||
"expected": 0 | ||
}, | ||
{ | ||
"uuid": "36549237-f765-4a4c-bfd9-5d3a8f7b07d2", | ||
"reimplements": "613b20b7-1873-4070-a3a6-70ae5f50d7cc", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input." | ||
], | ||
"description": "empty list", | ||
"property": "foldl", | ||
"input": { | ||
"list": [], | ||
"initial": 2, | ||
"function": "(acc, el) -> el * acc" | ||
}, | ||
"expected": 2 | ||
}, | ||
{ | ||
"uuid": "7a626a3c-03ec-42bc-9840-53f280e13067", | ||
"reimplements": "e56df3eb-9405-416a-b13a-aabb4c3b5194", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input." | ||
], | ||
"description": "direction independent function applied to non-empty list", | ||
"property": "foldl", | ||
"input": { | ||
"list": [1, 2, 3, 4], | ||
"initial": 5, | ||
"function": "(acc, el) -> el + acc" | ||
}, | ||
"expected": 15 | ||
}, | ||
{ | ||
"uuid": "d7fcad99-e88e-40e1-a539-4c519681f390", | ||
"reimplements": "d2cf5644-aee1-4dfc-9b88-06896676fe27", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input. Expects / to preserve fractions. Integer division", | ||
"will not work here, since it would compute 1 / 24 = 0. Use the ", | ||
"original test values (d2cf5644-aee1-4dfc-9b88-06896676fe27) if ", | ||
"integer division is expected / required. " | ||
], | ||
"description": "direction dependent function applied to non-empty list", | ||
"property": "foldl", | ||
"input": { | ||
"list": [1, 2, 3, 4], | ||
"initial": 24, | ||
"function": "(acc, el) -> el / acc" | ||
}, | ||
"expected": 64 | ||
SleeplessByte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
] | ||
}, | ||
{ | ||
"description": "folds (reduces) the given list from the right with a function", | ||
"comments": [ | ||
"For function: acc is the accumulator and el is the current element ", | ||
"The order of the arguments (ie. acc, el or el, acc) should match the ", | ||
"conventions common to the language of the track implementing this. ", | ||
"See https://github.com/exercism/problem-specifications/pull/1746#discussion_r548303995 for further advice." | ||
], | ||
"cases": [ | ||
{ | ||
"uuid": "aeb576b9-118e-4a57-a451-db49fac20fdc", | ||
|
@@ -222,13 +288,67 @@ | |
{ | ||
"uuid": "be396a53-c074-4db3-8dd6-f7ed003cce7c", | ||
"description": "direction dependent function applied to non-empty list", | ||
"comments": [ | ||
"Expects integer division (expects / to discard fractions). " | ||
], | ||
"property": "foldr", | ||
"input": { | ||
"list": [2, 5], | ||
"initial": 5, | ||
"function": "(x, y) -> x / y" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for posterity: The possible ambiguous interpretation for this function were:
So clearly the latter was intended. Note that this is different from the other case, where the former was intended. The fact that these two same strings require two different interpretations is what's confusing and is the motivation for this PR. |
||
}, | ||
"expected": 2 | ||
}, | ||
{ | ||
"uuid": "17214edb-20ba-42fc-bda8-000a5ab525b0", | ||
"reimplements": "aeb576b9-118e-4a57-a451-db49fac20fdc", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input." | ||
], | ||
"description": "empty list", | ||
"property": "foldr", | ||
"input": { | ||
"list": [], | ||
"initial": 2, | ||
"function": "(acc, el) -> el * acc" | ||
}, | ||
"expected": 2 | ||
}, | ||
{ | ||
"uuid": "e1c64db7-9253-4a3d-a7c4-5273b9e2a1bd", | ||
"reimplements": "c4b64e58-313e-4c47-9c68-7764964efb8e", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input." | ||
], | ||
"description": "direction independent function applied to non-empty list", | ||
"property": "foldr", | ||
"input": { | ||
"list": [1, 2, 3, 4], | ||
"initial": 5, | ||
"function": "(acc, el) -> el + acc" | ||
}, | ||
"expected": 15 | ||
}, | ||
{ | ||
"uuid": "8066003b-f2ff-437e-9103-66e6df474844", | ||
"reimplements": "be396a53-c074-4db3-8dd6-f7ed003cce7c", | ||
"comments": [ | ||
"Reimplemented to remove ambiguity about the parameters of the ", | ||
"function input. Expects / to preserve fractions. Integer division", | ||
"will not work here, since it would compute 4 / 24 = 1 / 6. Use ", | ||
"the original test values (be396a53-c074-4db3-8dd6-f7ed003cce7c) ", | ||
"if integer division is expected / required." | ||
], | ||
"description": "direction dependent function applied to non-empty list", | ||
"property": "foldr", | ||
"input": { | ||
"list": [1, 2, 3, 4], | ||
"initial": 24, | ||
"function": "(acc, el) -> el / acc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The follow comment concerns notation only. It does not change the expected values of any test, or change the semantics of how I understand that some track maintainers may disagree about whether the function argument list should be represented as a string as I advise implementing tracks to be aware of the conventions common to their language do what makes sense for their language. Why do I bring this up? Observe:
As you can see, I've listed three different languages doing things in three different ways, so I advise track maintainers looking to squabble over this that there is no universal convention, so we should just pick one for problem-specifications and run with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great advice and I agree 100% with it. I'll link this comment in the comments in the canonical data. |
||
}, | ||
"expected": 9 | ||
} | ||
] | ||
}, | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for posterity: The possible ambiguous interpretation for this function were:
So clearly the former was intended. Note that this is different from the other case, where the latter was intended. The fact that these two same strings require two different interpretations is what's confusing and is the motivation for this PR.