/
GridTests.elm
72 lines (60 loc) · 2.13 KB
/
GridTests.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module GridTests exposing (..)
import Expect
import Fuzz exposing (Fuzzer)
import Grid exposing (Grid)
import Test exposing (..)
getTest : Test
getTest =
let
overInUnderFuzzer =
Fuzz.intRange -1 1
in
describe "get"
[ fuzz2 overInUnderFuzzer overInUnderFuzzer "only returns values in bounds" <|
\row column ->
let
grid =
Grid.initialize { rows = 1, columns = 1 } (always ())
in
if row == 0 && column == 0 then
Expect.equal (Just ()) (Grid.get { row = row, column = column } grid)
else
Expect.equal Nothing (Grid.get { row = row, column = column } grid)
]
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)