File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
1
{-# LANGUAGE TemplateHaskell #-}
2
+ {-# LANGUAGE TypeApplications #-}
2
3
module Geometry.Plane.Test
3
4
( tests
4
5
) where
@@ -7,15 +8,21 @@ import Geometry.Plane
7
8
import Hedgehog
8
9
import qualified Hedgehog.Gen as Gen
9
10
import qualified Hedgehog.Range as Range
11
+ import Linear.Metric
10
12
import Linear.V2
11
13
12
14
prop_signedDistance_identity = property $ do
13
15
v <- forAll $ v2 coord
14
16
n <- forAll $ v2 (nonZero coord)
15
17
signedDistance v n v === 0
16
18
19
+ prop_signedDistance_unit = property $ do
20
+ v <- forAll $ v2 coord
21
+ n <- signorm <$> forAll (v2 (nonZero coord))
22
+ roundToPlaces 5 (signedDistance v n (v + n)) === 1
23
+
17
24
18
- coord :: MonadGen m => m Rational
25
+ coord :: MonadGen m => m Double
19
26
coord = Gen. realFrac_ (Range. linearFracFrom 0 (- 100 ) 100 )
20
27
21
28
nonZero :: (MonadGen m , Num a , Eq a ) => m a -> m a
@@ -27,3 +34,9 @@ v2 g = V2 <$> g <*> g
27
34
28
35
tests :: IO Bool
29
36
tests = checkParallel $$ (discover)
37
+
38
+
39
+ roundToPlaces :: RealFrac a => Int -> a -> a
40
+ roundToPlaces p x = fromInteger (round (x * p')) / p'
41
+ where
42
+ p' = 10 ^ p
You can’t perform that action at this time.
0 commit comments