import Test.Framework (defaultMain, testGroup) import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.Framework.Providers.HUnit import Test.HUnit import Test.QuickCheck import Test.QuickCheck.Gen import qualified Data.Vector as V import Puzzle hiding (main) instance Arbitrary Puzzle where arbitrary = do size <- choose (2, 4) board <- shuffle [0 .. (size*size - 1)] return $ Puzzle size (V.fromList board) False tests = [ testGroup "Board" [ testProperty "neighbors have distance of 1" prop_neighborDistance, testProperty "can solve puzzle" prop_canSolvePuzzle, testCase "basic distance" test_distance ] ] test_distance = distance puzzle @?= 4 where puzzle = Puzzle 2 (V.fromList [1, 3, 2, 0]) False prop_neighborDistance p = all validNeighbor (neighbors p) where validNeighbor n = abs (distance p - distance n) == 1 prop_canSolvePuzzle = not . null . solve example = Puzzle 2 (V.fromList [1, 3, 2, 0]) False main = do print example putStrLn "Neighbors:" mapM_ print (neighbors example) putStrLn "" defaultMain tests