summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2017-11-20 13:51:51 +0100
committerCamil Staps2017-11-20 13:51:51 +0100
commit8c77a8f0b70a2621be144cf521a7dc4347d40dc8 (patch)
tree71c67d4e319cf8995264c8c0140cc5501b18a2f6
parentAdd prop_no_pawns_on_1_and_8 (diff)
parentMerge branch '1-quickcheck-property-niet-meer-stukken-op-het-bord-na-een-zet'... (diff)
Merge branch 'master' into 5-quickcheck-property-there-can-never-be-a-pawn-on-rank-a-and-h
-rw-r--r--test/Test.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/Test.hs b/test/Test.hs
index 9cf10b4..d758d2b 100644
--- a/test/Test.hs
+++ b/test/Test.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TemplateHaskell, ParallelListComp #-}
-- vim: sw=2 ts=2 et ai:
module Test where
@@ -28,6 +28,17 @@ atAnyState ok pgn = and [ok b | Right b <- seqList [moveSAN m | m <- moves pgn]
seqList _ (Left _) = []
seqList [] _ = []
+atAnyTwoStates :: (Board -> Board -> Bool) -> PGN -> Bool
+atAnyTwoStates ok pgn =
+ let moveList = seqList [moveSAN m | m <- moves pgn] $ Right defaultBoard in
+ and [ok b1 b2 | Right b1 <- moveList | Right b2 <- tail moveList]
+ where
+ seqList :: [r -> Either e r] -> Either e r -> [Either e r]
+ seqList (f:fs) (Right io) = f io:seqList fs (f io)
+ seqList _ (Left _) = []
+ seqList [] _ = []
+
+
prop_checkPGN :: PGN -> Bool
prop_checkPGN pgn
| isLeft parsed = False
@@ -89,5 +100,12 @@ prop_no_pawns_on_1_and_8 = atAnyState $ all notOnAorH . pieceCoords Nothing (Jus
notOnAorH :: ((Int,Int),a) -> Bool
notOnAorH ((_,r),_) = r /= 0 && r /= 7
+prop_number_of_pieces :: PGN -> Bool
+prop_number_of_pieces = atAnyTwoStates (\b1 b2 ->
+ length (pieceCoords Nothing Nothing b1) == length (pieceCoords Nothing Nothing b2)
+ ||
+ length (pieceCoords Nothing Nothing b1) - 1 == length (pieceCoords Nothing Nothing b2)
+ )
+
return []
main = $forAllProperties (quickCheckWithResult (stdArgs {maxSuccess=10000}))