From 4ef3aa7f1f4fafc384f405bc9f8cfc95cd0a74ac Mon Sep 17 00:00:00 2001 From: hasufell Date: Wed, 17 Dec 2014 22:26:40 +0100 Subject: [PATCH] TESTS: add more function documentation --- Test/Vector.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Test/Vector.hs b/Test/Vector.hs index 49dec4b..55f62a7 100644 --- a/Test/Vector.hs +++ b/Test/Vector.hs @@ -19,60 +19,79 @@ instance Arbitrary P2 where arbitrary = curry p2 <$> arbitrary <*> arbitrary +-- the point describing the lower left corner of the square +-- must be part of the square inRangeProp1 :: Square -> Bool inRangeProp1 sq@((x1, y1), _) = inRange sq (p2 (x1, y1)) +-- the point describing the upper right corner of the square +-- must be part of the square inRangeProp2 :: Square -> Bool inRangeProp2 sq@(_, (x2, y2)) = inRange sq (p2 (x2, y2)) +-- the point describing the upper left corner of the square +-- must be part of the square inRangeProp3 :: Square -> Bool inRangeProp3 sq@((x1, _), (_, y2)) = inRange sq (p2 (x1, y2)) +-- the point describing the lower right corner of the square +-- must be part of the square inRangeProp4 :: Square -> Bool inRangeProp4 sq@((_, y1), (x2, _)) = inRange sq (p2 (x2, y1)) +-- generating random points within the square inRangeProp5 :: Square -> Positive Double -> Positive Double -> Bool inRangeProp5 sq@((x1, y1), (x2, y2)) (Positive a) (Positive b) = inRange sq (p2 (x1 + ((x2 - x1) / (a + 1)), y1 + ((y2 - y1) / (b + 1)))) +-- apply id function on the point onPTProp1 :: PT -> Bool onPTProp1 pt = onPT id pt == pt +-- add a random value to the point coordinates onPTProp2 :: PT -> Positive R2 -> Bool onPTProp2 pt (Positive (R2 rx ry)) = onPT (\(x, y) -> (x + rx, y + ry)) pt /= pt +-- angle between two vectors both on the x-axis must be 0 getAngleProp1 :: Positive Vec -> Positive Vec -> Bool getAngleProp1 (Positive (R2 x1 _)) (Positive (R2 x2 _)) = getAngle (R2 x1 0) (R2 x2 0) == 0 +-- angle between two vectors both on the y-axis must be 0 getAngleProp2 :: Positive Vec -> Positive Vec -> Bool getAngleProp2 (Positive (R2 _ y1)) (Positive (R2 _ y2)) = getAngle (R2 0 y1) (R2 0 y2) == 0 +-- angle between two vectors both on the x-axis but with opposite direction +-- must be pi getAngleProp3 :: Positive Vec -> Positive Vec -> Bool getAngleProp3 (Positive (R2 x1 _)) (Positive (R2 x2 _)) = getAngle (R2 (negate x1) 0) (R2 x2 0) == pi +-- angle between two vectors both on the y-axis but with opposite direction +-- must be pi getAngleProp4 :: Positive Vec -> Positive Vec -> Bool getAngleProp4 (Positive (R2 _ y1)) (Positive (R2 _ y2)) = getAngle (R2 0 (negate y1)) (R2 0 y2) == pi +-- angle between vector in x-axis direction and y-axis direction must be +-- p/2 getAngleProp5 :: Positive Vec -> Positive Vec -> Bool getAngleProp5 (Positive (R2 x1 _)) (Positive (R2 _ y2)) = getAngle (R2 x1 0) (R2 0 y2) == pi / 2