Skip to content

Commit

Permalink
list-ops: reimplement ambiguous tests (exercism#1746)
Browse files Browse the repository at this point in the history
* Format

* Re-implement ambigious test cases

* Clarifying comment

* Re-add old versions of reimplemented tests

* Remove accidantally commited executable

* Clarifying commentary about integer division.

* Add advice
  • Loading branch information
SleeplessByte authored Dec 24, 2020
1 parent fcc6028 commit bb38e15
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions exercises/list-ops/canonical-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
]
},
{
"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",
Expand All @@ -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"
},
"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"
},
"expected": 9
}
]
},
Expand Down

0 comments on commit bb38e15

Please sign in to comment.