Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use a 1-dimensional array for Grid. Waaaaay faster!
- Loading branch information
1 parent
2a21e42
commit 50d0504
Showing
2 changed files
with
133 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module GridTests exposing (..) | ||
|
||
import Expect | ||
import Fuzz exposing (Fuzzer) | ||
import Grid exposing (Grid) | ||
import Test exposing (..) | ||
|
||
|
||
getAndSetTest : Test | ||
getAndSetTest = | ||
fuzz coordsFuzzer "setting a value and then getting the same value should work" <| | ||
\coords -> | ||
blank10x10 | ||
|> Grid.set coords 1 | ||
|> Grid.get coords | ||
|> Expect.equal (Just 1) | ||
|
||
|
||
windowsTest : Test | ||
windowsTest = | ||
describe "windows" | ||
[ test "creates a moving window over the grid data" <| | ||
\_ -> | ||
Grid.fromRowsAndColumns | ||
[ [ 1, 2 ] | ||
, [ 3, 4 ] | ||
] | ||
|> Grid.windows { width = 2, height = 2 } | ||
|> Expect.equal | ||
(Grid.fromRowsAndColumns | ||
[ [ Grid.fromRowsAndColumns [ [ 1, 2 ], [ 3, 4 ] ] | ||
, Grid.fromRowsAndColumns [ [ 2, 1 ], [ 4, 3 ] ] | ||
] | ||
, [ Grid.fromRowsAndColumns [ [ 3, 4 ], [ 1, 2 ] ] | ||
, Grid.fromRowsAndColumns [ [ 4, 3 ], [ 2, 1 ] ] | ||
] | ||
] | ||
) | ||
] | ||
|
||
|
||
blank10x10 : Grid Int | ||
blank10x10 = | ||
Grid.initialize { rows = 10, columns = 10 } (always 0) | ||
|
||
|
||
coordsFuzzer : Fuzzer { row : Int, column : Int } | ||
coordsFuzzer = | ||
Fuzz.map2 (\row column -> { row = row, column = column }) | ||
(Fuzz.intRange 0 9) | ||
(Fuzz.intRange 0 9) |