Skip to content

Commit 97cbc3c

Browse files
committed
Use a helper to round values.
1 parent c34ed71 commit 97cbc3c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/Geometry/Plane/Test.hs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12
{-# LANGUAGE TemplateHaskell #-}
23
{-# LANGUAGE TypeApplications #-}
34
module Geometry.Plane.Test
@@ -19,7 +20,7 @@ prop_signedDistance_identity = property $ do
1920
prop_signedDistance_unit = property $ do
2021
v <- forAll $ v2 coord
2122
n <- signorm <$> forAll (v2 (nonZero coord))
22-
roundToPlaces 5 (signedDistance v n (v + n)) === 1
23+
Near (signedDistance v n (v + n)) === 1
2324

2425

2526
coord :: MonadGen m => m Double
@@ -40,3 +41,10 @@ roundToPlaces :: RealFrac a => Int -> a -> a
4041
roundToPlaces p x = fromInteger (round (x * p')) / p'
4142
where
4243
p' = 10 ^ p
44+
45+
46+
newtype Near a = Near a
47+
deriving (Num, Show)
48+
49+
instance RealFrac a => Eq (Near a) where
50+
Near a == Near b = roundToPlaces 5 a == roundToPlaces 5 b

0 commit comments

Comments
 (0)