Skip to content

Commit d5f9650

Browse files
authored
saddle-points/test: Do not use head on empty list (#1138)
The case with input `[]` does not work well with the `columns = length $ head xss`. It's somewhat hard to have an implementation that actually causes `head []` to be evalauted, but an example implementation that in fact does is: ```haskell saddlePoints arr = if snd (snd (bounds arr)) == 3 then [(2, 1)] else [] ``` Since there is a possible implementation that could cause `head []` to be evaluated, we should rewrite it so that we never use `head` on an empty list.
1 parent 322ee64 commit d5f9650

File tree

1 file changed

+1
-1
lines changed
  • exercises/practice/saddle-points/test

1 file changed

+1
-1
lines changed

exercises/practice/saddle-points/test/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ specs = describe "saddlePoints" $ for_ cases test
1818
where
1919
assertion = saddlePoints matrix `shouldBe` expected
2020
rows = length xss
21-
columns = length $ head xss
21+
columns = if null xss then 0 else length $ head xss
2222
matrix = listArray ((1, 1), (rows, columns)) (concat xss)
2323

2424
cases = [ ( "Example from README",

0 commit comments

Comments
 (0)