diff options
author | Camil Staps | 2017-11-13 14:37:39 +0100 |
---|---|---|
committer | Camil Staps | 2017-11-13 14:37:39 +0100 |
commit | 88093d0614a25494417d37970b638975fbdcd1fd (patch) | |
tree | b6f90a257cca58cafafca6b2193c7c576f51a29d /test/test_parser.hs | |
parent | Assignment 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.hs | 16 |
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 |