Skip to content

Commit

Permalink
figure out further issues in get
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Feb 21, 2020
1 parent 2186d69 commit 7da990b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Grid.elm
Expand Up @@ -159,7 +159,9 @@ cropWrapping bounds (Grid grid) =

get : { row : Int, column : Int } -> Grid a -> Maybe a
get coords (Grid { items, width }) =
if coords.row < 0 || coords.column < 0 then
-- we don't need to check row; a row above the max will be a Nothing in the
-- lookup below anyway.
if coords.row < 0 || coords.column < 0 || coords.column > width - 1 then
Nothing

else
Expand Down
22 changes: 22 additions & 0 deletions tests/GridTests.elm
Expand Up @@ -111,6 +111,28 @@ compatibilityTest =
|> Grid.toArrays
in
Expect.equal expected actual
, fuzz2
(Fuzz.map2 (\rows columns -> { rows = rows, columns = columns })
(Fuzz.intRange 0 2)
(Fuzz.intRange 0 2)
)
(Fuzz.map2 (\row column -> { row = row, column = column })
(Fuzz.intRange -1 3)
(Fuzz.intRange -1 3)
)
"get"
<|
\size coords ->
let
expected =
SlowGrid.initialize size identity
|> SlowGrid.get coords

actual =
Grid.initialize size identity
|> Grid.get coords
in
Expect.equal expected actual
]


Expand Down

0 comments on commit 7da990b

Please sign in to comment.