Skip to content

Commit

Permalink
binary-search: Use error object instead of sentinel -1 (#1338)
Browse files Browse the repository at this point in the history
binary-search 1.2.0

As discussed in
#1312

Although -1 is a sentinel value, using this sentinel value is not the
usual course of action in some languages. In using an error object, we
avoid giving the wrong idea that we are requiring the use of the
sentinel value.

This error value was defined in
#401

Of course, languages that wish to use a sentinel value may continue to
do so; this commit is not intended to decree that sentinel values are
forbidden.

Neither is this commit decreeing that all languages must represent this
condition as an error; it is simply a declaration that this condition
bears enough consideration that we'll represent it with a different
type.

Closes #1312
Checks the related box in #1311
  • Loading branch information
petertseng authored Sep 24, 2018
1 parent 258c807 commit e0ffb00
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions exercises/binary-search/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"exercise": "binary-search",
"version": "1.1.0",
"version": "1.2.0",
"comments": [
"Here -1 is used to indicate that the value is not included in the array.",
"The error object is used to indicate that the value is not included in the array.",
"It should be replaced with the respective expression that is idiomatic",
"for the language that implements the tests.",

Expand Down Expand Up @@ -77,7 +77,7 @@
"array": [1, 3, 4, 6, 8, 9, 11],
"value": 7
},
"expected": -1
"expected": {"error": "value not in array"}
},
{
"description": "a value smaller than the array's smallest value is not included",
Expand All @@ -86,7 +86,7 @@
"array": [1, 3, 4, 6, 8, 9, 11],
"value": 0
},
"expected": -1
"expected": {"error": "value not in array"}
},
{
"description": "a value larger than the array's largest value is not included",
Expand All @@ -95,7 +95,7 @@
"array": [1, 3, 4, 6, 8, 9, 11],
"value": 13
},
"expected": -1
"expected": {"error": "value not in array"}
},
{
"description": "nothing is included in an empty array",
Expand All @@ -104,7 +104,7 @@
"array": [],
"value": 1
},
"expected": -1
"expected": {"error": "value not in array"}
}
]
}

0 comments on commit e0ffb00

Please sign in to comment.