Skip to content

Commit

Permalink
tests: use approximate comparison instead of == for Doubles
Browse files Browse the repository at this point in the history
Fixes #288.
  • Loading branch information
byorgey committed May 29, 2017
1 parent e4745fe commit 9579fb2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/Diagrams/Test/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ tests = testGroup "Transform" [
testProperty "rotating a vector by a number then its additive inverse will yield the original vector" $
\θ a -> rotate ((θ * (-1)) @@ deg) (rotate ((θ :: Double) @@ deg) (a :: V2 Double)) =~ a
, testProperty "under rotated allows scaling along an angle" $
\θ f a -> under (rotated ((θ :: Double) @@ deg)) (scaleX (f :: Double)) (a :: V2 Double) == (rotate (negated (θ @@ deg)) . (scaleX f) . rotate (θ @@ deg)) a
\θ f a -> under (rotated ((θ :: Double) @@ deg)) (scaleX (f :: Double)) (a :: V2 Double) =~ (rotate (negated (θ @@ deg)) . (scaleX f) . rotate (θ @@ deg)) a
, testProperty "a rotation of 0 does nothing" $
\a -> rotate (0 @@ deg) (a :: V2 Double) =~ a
, testProperty "adding 360 degrees to a turn does nothing" $
\c a -> rotate (((c :: Double) + 360) @@ deg) (a :: V2 Double) =~ rotate (c @@ deg) a
, testProperty "over rotated allows scaling along x of a rotated shape" $
\θ f a -> over (rotated ((θ :: Double) @@ deg)) (scaleX (f :: Double)) (a :: V2 Double) == (rotate (θ @@ deg) . (scaleX f) . rotate (negated (θ @@ deg))) a
\θ f a -> over (rotated ((θ :: Double) @@ deg)) (scaleX (f :: Double)) (a :: V2 Double) =~ (rotate (θ @@ deg) . (scaleX f) . rotate (negated (θ @@ deg))) a
, testProperty "scaleX" $
\f a b -> (scaleX (f :: Double)) (V2 (a :: Double) b) == V2 (a * f) b
\f a b -> (scaleX (f :: Double)) (V2 (a :: Double) b) =~ V2 (a * f) b
, testProperty "scaleY" $
\f a b -> (scaleY (f :: Double)) (V2 (a :: Double) b) == V2 a (f * b)
\f a b -> (scaleY (f :: Double)) (V2 (a :: Double) b) =~ V2 a (f * b)
, testProperty "reflectX" $
\a b -> reflectX (V2 (a :: Double) b) == V2 (a * (-1)) b
\a b -> reflectX (V2 (a :: Double) b) =~ V2 (a * (-1)) b
, testProperty "reflectY" $
\a b -> reflectY (V2 (a :: Double) b) == V2 a ((-1) * b)
\a b -> reflectY (V2 (a :: Double) b) =~ V2 a ((-1) * b)
, testProperty "reflectXY" $
\a b -> reflectXY (V2 (a :: Double) b) == V2 b a
\a b -> reflectXY (V2 (a :: Double) b) =~ V2 b a
, testProperty "translate" $
\a b c d -> translateX (a :: Double) (translateY b (P (V2 c d ))) == P (V2 (a + c) (b + d))
\a b c d -> translateX (a :: Double) (translateY b (P (V2 c d ))) =~ P (V2 (a + c) (b + d))
, testProperty "shear" $
\a b c d -> shearX (a :: Double) (shearY b (V2 c d)) == V2 ((c*b + d) * a + c) (c*b + d)
\a b c d -> shearX (a :: Double) (shearY b (V2 c d)) =~ V2 ((c*b + d) * a + c) (c*b + d)
, testProperty "(1,0) rotateTo some dir will return normalised dir" $
\(NonZero a) b -> rotateTo (dir (V2 (a :: Double) b)) (V2 1 0) =~ signorm (V2 a b)
, testProperty "rotates" $
\a c -> rotate ((a :: Double)@@ deg) (c :: V2 Double) == rotate'' ((a :: Double)@@ deg) (c :: V2 Double) && rotate ((a :: Double)@@ deg) (c :: V2 Double) == rotate' ((a :: Double)@@ deg) (c :: V2 Double)
\a c -> rotate ((a :: Double)@@ deg) (c :: V2 Double) =~ rotate'' ((a :: Double)@@ deg) (c :: V2 Double) && rotate ((a :: Double)@@ deg) (c :: V2 Double) =~ rotate' ((a :: Double)@@ deg) (c :: V2 Double)
, testProperty "reflectAbout works for a vector" $
\a b c d e f -> reflectAbout (P (V2 (a :: Double) b)) (dir (V2 c d)) (V2 e f) =~ over (rotated (atan2A' d c)) reflectY (V2 e f)
, testProperty "reflectAbout works for a point" $
Expand Down

0 comments on commit 9579fb2

Please sign in to comment.