fixed

Pure Haskell large fixed-width integers.
git clone git://git.ppad.tech/fixed.git
Log | Files | Refs | README | LICENSE

commit 896945138f8bb4c3b6f3fca41164e53d4ac8e190
parent b4eddf48496f541180b1b9aae4e96635b0de4247
Author: Jared Tobin <jared@jtobin.io>
Date:   Thu, 23 Jan 2025 09:34:43 +0400

test: comparison tests

Diffstat:
Mtest/Main.hs | 30+++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/test/Main.hs b/test/Main.hs @@ -20,6 +20,15 @@ instance Q.Arbitrary Word256 where w3 <- Q.arbitrary pure (Word256 w0 w1 w2 w3) +newtype Different a = Different (a, a) + deriving Show + +instance (Q.Arbitrary a, Eq a) => Q.Arbitrary (Different a) where + arbitrary = do + a <- Q.arbitrary + b <- Q.arbitrary `Q.suchThat` (\b -> b /= a) + pure (Different (a, b)) + -- second argument is no greater than first argument newtype Monotonic a = Monotonic (a, a) deriving Show @@ -44,6 +53,16 @@ instance Q.Arbitrary MulMonotonic where -- properties ----------------------------------------------------------------- +lt_matches :: Different (Q.NonNegative Integer) -> Bool +lt_matches (Different (Q.NonNegative a, Q.NonNegative b)) + | a < b = to_word256 a `lt` to_word256 b + | otherwise = to_word256 b `lt` to_word256 a + +gt_matches :: Different (Q.NonNegative Integer) -> Bool +gt_matches (Different (Q.NonNegative a, Q.NonNegative b)) + | a > b = to_word256 a `gt` to_word256 b + | otherwise = to_word256 b `gt` to_word256 a + mul_c_matches :: Word64 -> Word64 -> Bool mul_c_matches a b = let c = fi a * fi b :: Integer @@ -140,6 +159,14 @@ recip_2by1_case1 = do -- main ----------------------------------------------------------------------- +comparison :: TestTree +comparison = testGroup "comparison" [ + Q.testProperty "lt matches" $ + Q.withMaxSuccess 1000 lt_matches + , Q.testProperty "gt matches" $ + Q.withMaxSuccess 1000 gt_matches + ] + bits :: TestTree bits = testGroup "bits" [ Q.testProperty "or matches" $ @@ -184,7 +211,8 @@ main :: IO () main = defaultMain $ testGroup "ppad-fixed" [ testGroup "property tests" [ - utils + comparison + , utils , inverses , bits , arithmetic