Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bullet-proofing and testing coverage.
- Converted the various index to square and algebraic squares to use Maybe types and handle errors sensibly. - Added tests for a few missing items and cleaned up some of the existing tests a bit. - Ran HPC reports on the whole thing and, aside from a few unused Show instances and one thunk in some (intentionally) bad data, everything is executed by the test suite.
- Loading branch information
Showing
8 changed files
with
158 additions
and
67 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -4,4 +4,5 @@ html/ | ||
*.hi | *.hi | ||
*.o | *.o | ||
*.tix | *.tix | ||
Suite | |||
|
|
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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
{- Some QuickCheck generators and other utility functions used in a few test | |||
- modules. | |||
-} | |||
|
|||
module ChessTools.Test.Utils ( | |||
boardSizeGen | |||
, genIndex | |||
, genBadIndex | |||
, genSquare | |||
) where | |||
|
|||
import Test.QuickCheck | |||
|
|||
import ChessTools.Board | |||
import ChessTools.Board.Internal | |||
|
|||
|
|||
-- This could be an Arbitrary instance, but it would be an orphan. We don't | |||
-- want to put the instance in ChessTools.Board.Internal to avoid unnecessary | |||
-- QuickCheck dependencies, so prefer to use a direct Gen function here. | |||
boardSizeGen :: Gen BoardSize | |||
boardSizeGen = sized $ \n -> do | |||
let n' = n + 2 | |||
dx <- choose (2, n') | |||
dy <- choose (2, n') | |||
vbuf <- choose (0, 4) | |||
return $ BoardSize dx dy vbuf | |||
|
|||
genIndex :: BoardSize -> Gen BIndex | |||
genIndex bs = do | |||
Square (dx, dy) <- genSquare bs | |||
return $ BI ((dy + boardVertBuffer bs) * rowLength bs + dx + leftBuf bs) | |||
|
|||
genBadIndex :: BoardSize -> Gen BIndex | |||
genBadIndex (BoardSize h v vbuf) | |||
| vbuf == 0 = leftBuffer | |||
| otherwise = oneof [leftBuffer, above, below] | |||
where rl = 2 * h - 1 | |||
leftBuffer = do | |||
x <- choose (0, v - 1) | |||
y <- choose (0, h `div` 2 - 1) | |||
return $ BI ((vbuf + x) * rl + y) | |||
|
|||
above = do | |||
x <- choose (0, vbuf - 1) | |||
y <- choose (0, rl - 1) | |||
return $ BI ((vbuf + v + x) * rl + y) | |||
|
|||
below = do | |||
x <- choose (0, vbuf - 1) | |||
y <- choose (0, rl - 1) | |||
return $ BI (x * rl + y) | |||
|
|||
genSquare :: BoardSize -> Gen Square | |||
genSquare bs = do | |||
sx <- choose (0, boardHorizSize bs - 1) | |||
sy <- choose (0, boardVertSize bs - 1) | |||
return $ Square (sx, sy) | |||
|
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