summaryrefslogtreecommitdiff
path: root/test/test_parser.hs
diff options
context:
space:
mode:
authorCamil Staps2017-11-13 14:37:39 +0100
committerCamil Staps2017-11-13 14:37:39 +0100
commit88093d0614a25494417d37970b638975fbdcd1fd (patch)
treeb6f90a257cca58cafafca6b2193c7c576f51a29d /test/test_parser.hs
parentAssignment 3: Write small section on QuickCheck and relation to assignment 1 (diff)
Add frequency-based arbitrary move generator
Diffstat (limited to 'test/test_parser.hs')
-rw-r--r--test/test_parser.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/test/test_parser.hs b/test/test_parser.hs
index e34218b..de9883e 100644
--- a/test/test_parser.hs
+++ b/test/test_parser.hs
@@ -14,11 +14,25 @@ import Chess
import Chess.FEN
import Chess.PGN
+import qualified ArbitraryMove as AM
+
deriving instance Eq PGN
instance Arbitrary GameResult where arbitrary = elements [BlackWon, WhiteWon, Draw]
instance Arbitrary Board where arbitrary = return defaultBoard
-arbitraryMove = return "e4"
+
+type Move = String
+
+arbitraryMove :: Gen Move
+arbitraryMove = frequency
+ [ (2, AM.arbitraryMove)
+ , (1, invalidMove)
+ ]
+ where
+ invalidMove :: Gen Move
+ invalidMove = oneof
+ [ liftM2 (\r c -> [r,c]) (choose ('i', 'z')) (elements "09")
+ ]
instance Arbitrary PGN
where