aboutsummaryrefslogtreecommitdiff
path: root/test/Util.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2026-01-16 11:57:44 +0100
committerTom Smeding <tom@tomsmeding.com>2026-01-16 11:57:44 +0100
commit411d563023c65270aca746f12c4d597b49122b45 (patch)
tree1a1850333050460d149665ef0ae4b4016df27754 /test/Util.hs
parentd1e2e280644baece2cabb075d566d99cc2c27019 (diff)
test: Port sum tests to sumAll
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