aboutsummaryrefslogtreecommitdiff
path: root/test/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'test/Util.hs')
-rw-r--r--test/Util.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/Util.hs b/test/Util.hs
index 8a5ba72..6514fbf 100644
--- a/test/Util.hs
+++ b/test/Util.hs
@@ -36,16 +36,20 @@ orSumOuter1 (sn@SNat :: SNat n) =
let n = fromSNat' sn
in OR.rerank @n @1 @0 (OR.scalar . OR.sumA) . OR.transpose ([1 .. n] ++ [0])
-class AlmostEq f where
- type AlmostEqConstr f :: Type -> Constraint
+class AlmostEq t where
+ type EltOf t :: Type
-- | absolute tolerance, lhs, rhs
- almostEq :: (AlmostEqConstr f a, Ord a, Show a, Fractional a, MonadTest m)
- => a -> f a -> f a -> m ()
+ almostEq :: MonadTest m => EltOf t -> t -> t -> m ()
-instance AlmostEq (OR.Array n) where
- type AlmostEqConstr (OR.Array n) = OR.Unbox
+instance (OR.Unbox a, Ord a, Show a, Fractional a) => AlmostEq (OR.Array n a) where
+ type EltOf (OR.Array n a) = a
almostEq atol lhs rhs
| OR.allA (< atol) (OR.zipWithA (\a b -> abs (a - b)) rhs lhs) =
success
| otherwise =
failDiff lhs rhs
+
+instance AlmostEq Double where
+ type EltOf Double = Double
+ almostEq atol lhs rhs | abs (lhs - rhs) < atol = success
+ | otherwise = failDiff lhs rhs