From 0ce0a3b586317c6f1da73dabc0d255fa94cc70e8 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Tue, 21 Nov 2017 11:00:24 +0000 Subject: [PATCH] Add Arbitrary instance for Body and a property test --- test/Tests.hs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/Tests.hs b/test/Tests.hs index 17c81fe..6dd37be 100644 --- a/test/Tests.hs +++ b/test/Tests.hs @@ -42,7 +42,29 @@ unitTests = testGroup "Unit tests" $ updateAll 0 0.5 [earth] @?= [earth] ] +instance (Arbitrary a) => Arbitrary (V3 a) where + arbitrary = do + x <- arbitrary + y <- arbitrary + z <- arbitrary + return $ V3 x y z + +instance (Arbitrary (f a)) => Arbitrary (Point f a) where + arbitrary = do + x <- arbitrary + return $ P x + +instance Arbitrary Body where + arbitrary = do + name <- arbitrary + Positive radius <- arbitrary + Positive mass <- arbitrary + pos <- arbitrary + speed <- arbitrary + return $ Body name radius mass pos speed + propertyChecks :: TestTree propertyChecks = testGroup "Property tests (QuickCheck)" - [ + [ QC.testProperty "updateAll of a singleton" + $ \body -> updateAll 0 0.5 ([body] :: [Body]) == [body] ]