Skip to content

Commit

Permalink
change: Use error object instead of sentinel -1 (#1340)
Browse files Browse the repository at this point in the history
change 1.3.0

As proposed in
#1313
#905 (comment)

In contrast to the proposal in
#336 (comment)

Although -1 is a sentinel value, the sentinel value had been overloaded
in this JSON file to mean two separate conditions:

* "Can't make target" (ostensibly, we might be able to make the target
  with a different set of coins)
* "Target is negative" (no matter what coins we provide, this target is
  always invalid)

To make clear that these two conditions are different, we use an error
object describing each.

This error object was defined in
#401

Note that this commit is not a decree that all languages must represent
these conditions as errors; languages should continue to represent the
conditions in the usual way for that language. It is simply a
declaration that these two conditions bear enough consideration that
we'll represent them with a different type and also clearly
differentiate between the two.

Closes #1313
Checks the related box in #1311
  • Loading branch information
petertseng authored Sep 24, 2018
1 parent b7c10ae commit 258c807
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions exercises/change/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exercise": "change",
"version": "1.2.0",
"version": "1.3.0",
"comments": [
"Given an infinite supply of coins with different values, ",
"find the smallest number of coins needed to make a desired ",
Expand Down Expand Up @@ -88,7 +88,7 @@
"coins": [5, 10],
"target": 3
},
"expected": -1
"expected": {"error": "can't make target with given coins"}
},
{
"description": "error if no combination can add up to target",
Expand All @@ -97,7 +97,7 @@
"coins": [5, 10],
"target": 94
},
"expected": -1
"expected": {"error": "can't make target with given coins"}
},
{
"description": "cannot find negative change values",
Expand All @@ -106,7 +106,7 @@
"coins": [1, 2, 5],
"target": -5
},
"expected": -1
"expected": {"error": "target can't be negative"}
}
]
}

0 comments on commit 258c807

Please sign in to comment.