Skip to content

Commit

Permalink
Add First of Many Puzzle.solve Tests
Browse files Browse the repository at this point in the history
Addresses #10
  • Loading branch information
jehoshua02 committed Sep 16, 2016
1 parent e09989e commit fb0eef9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Sudoku/Puzzle.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ solve puzzle =
|> Possible.eliminateUsed
|> Possible.eliminateCrowds
|> Possible.eliminateSame
|> Possible.eliminateAligned
--|> Possible.eliminateAligned
in
if before == after then
Err Unsolvable
Expand Down
45 changes: 45 additions & 0 deletions src/Sudoku/PuzzleSolveTests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
port module Sudoku.PuzzleSolveTests exposing (tests)

import Test exposing (..)
import Expect
import Sudoku.Puzzle as Puzzle exposing (Error(..))
import Util exposing (set)


tests : Test
tests =
describe "Puzzle"
[ describe "solve"
([
{ id = "Sudoku #001 (Easy)"
, puzzle =
[1,3,0,2,0,0,7,4,0
,0,2,5,0,1,0,0,0,0
,4,8,0,0,6,0,0,5,0
,0,0,0,7,8,0,2,1,0
,5,0,0,0,9,0,3,7,0
,9,0,0,0,3,0,0,0,5
,0,4,0,0,0,6,8,9,0
,0,5,3,0,0,1,4,0,0
,6,0,0,0,0,0,0,0,0
]
, solution =
[1,3,6,2,5,9,7,4,8
,7,2,5,4,1,8,9,3,6
,4,8,9,3,6,7,1,5,2
,3,6,4,7,8,5,2,1,9
,5,1,8,6,9,2,3,7,4
,9,7,2,1,3,4,6,8,5
,2,4,1,5,7,6,8,9,3
,8,5,3,9,2,1,4,6,7
,6,9,7,8,4,3,5,2,1
]
}
] |> List.map
(\puzzle ->
test ("should solve " ++ puzzle.id) <|
\() ->
Expect.equal (Ok puzzle.solution) (Puzzle.solve puzzle.puzzle)
)
)
]
2 changes: 2 additions & 0 deletions tests/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Test exposing (..)
import Sudoku.PuzzleTests
import Sudoku.PossibleTests
import Sudoku.GridTests
import Sudoku.PuzzleSolveTests


tests : Test
Expand All @@ -15,6 +16,7 @@ tests =
[ Sudoku.GridTests.tests
, Sudoku.PuzzleTests.tests
, Sudoku.PossibleTests.tests
, Sudoku.PuzzleSolveTests.tests
]


Expand Down

0 comments on commit fb0eef9

Please sign in to comment.