-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.hs
50 lines (44 loc) · 1.59 KB
/
test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# Language FlexibleContexts #-}
{-# Language UndecidableInstances #-}
{-# Language GeneralizedNewtypeDeriving #-}
-- base
import Control.Applicative
-- lens
import Control.Lens
-- linear
import Linear
-- falling
import Falling
-- QuickCheck
import Test.QuickCheck
-- hspec
import Test.Hspec
instance Arbitrary a => Arbitrary (V3 a) where
arbitrary = V3 <$> arbitrary <*> arbitrary <*> arbitrary
instance Arbitrary n => Arbitrary (Particle n) where
arbitrary = Particle <$> arbitrary <*> arbitrary <*> arbitrary
-- | Stupid type to improve inference for QuickCheck things.
newtype Doubled f = D (f Double)
instance Show (f Double) => Show (Doubled f) where
show (D a) = show a
instance Arbitrary (f Double) => Arbitrary (Doubled f) where
arbitrary = D <$> arbitrary
main :: IO ()
main = hspec $ do
describe "gravitation" $ do
it "gravitation a a = V3 NaN NaN NaN." . property $
\(D a) -> allOf traverse isNaN $ gravitation a a
it "gravitation a b = negate (gravitation b a)." . property $
\(D a) b -> a == b ||
gravitation a b == negate (gravitation b a)
it "with a /= b, gravitation a b has no NaN." . property $
\(D a) b -> a == b ||
allOf traverse (not . isNaN) (gravitation a b)
describe "update" $ do
it "with a ^. mass /= 0, update [a] = [a]." . property $
\(D a) -> a ^. mass == 0 || update [a] == [a]
it "never produces NaNs." . property $
\as -> allOf (traverse . traverse) (not . isNaN)
$ update (as :: [Particle Double])
it "preserves length." . property $
\as -> length (update as) == length (as :: [Particle Double])