From 04332ff5dc10280e44ef148316010ce282620b95 Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 20 Nov 2017 13:37:47 +0100 Subject: Add number of pieces property test --- test/Test.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Test.hs b/test/Test.hs index c5c694e..e07fcc5 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -27,6 +27,15 @@ 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 = and [ok b1 b2 | Right b1 <- seqList [moveSAN m | m <- moves pgn] | Right b2 <- seqList [moveSAN m | m <- moves pgn] $ Right defaultBoard] + 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 @@ -75,5 +84,12 @@ prop_only_2_kings = atAnyState (\b -> where pieceCoords clr brd piece = [i | (i, pc) <- (assocs $ board brd), pc == Just (Piece clr piece)] +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})) -- cgit v1.2.3 From d21008807191c7e60984a5f5299321e4ca72502e Mon Sep 17 00:00:00 2001 From: Erin van der Veen Date: Mon, 20 Nov 2017 13:44:55 +0100 Subject: Fix issues in number of pieces property --- test/Test.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Test.hs b/test/Test.hs index 7155d84..6741e70 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 @@ -29,7 +29,9 @@ atAnyState ok pgn = and [ok b | Right b <- seqList [moveSAN m | m <- moves pgn] seqList [] _ = [] atAnyTwoStates :: (Board -> Board -> Bool) -> PGN -> Bool -atAnyTwoStates ok pgn = and [ok b1 b2 | Right b1 <- seqList [moveSAN m | m <- moves pgn] | Right b2 <- seqList [moveSAN m | m <- moves pgn] $ Right defaultBoard] +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) -- cgit v1.2.3