fixed

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

commit 7779ee3c471a4eb0e6a979d2590236637b07e2fb
parent 4bee193289b86adadbfc8144e9a17d9e4fe91099
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 12 Dec 2025 16:54:14 +0400

test: odd tests

Diffstat:
Mtest/Montgomery/Curve.hs | 4++++
Mtest/Wider.hs | 10++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/test/Montgomery/Curve.hs b/test/Montgomery/Curve.hs @@ -138,6 +138,9 @@ exp_matches a b = inv_valid :: Q.NonZero C.Montgomery -> Bool inv_valid (Q.NonZero s) = C.eq_vartime (C.inv s * s) 1 +odd_correct :: C.Montgomery -> Bool +odd_correct w = C.odd w == I.integerTestBit (W.from (C.from w)) 0 + tests :: TestTree tests = testGroup "montgomery tests (curve)" [ H.testCase "representation" repr @@ -148,5 +151,6 @@ tests = testGroup "montgomery tests (curve)" [ , Q.testProperty "a * b mod m ~ ma * mb" $ Q.withMaxSuccess 500 mul_matches , Q.testProperty "a ^ b mod m ~ ma ^ mb" $ Q.withMaxSuccess 500 exp_matches , Q.testProperty "n ^ -1 mod m * n ~ 1" $ Q.withMaxSuccess 500 inv_valid + , Q.testProperty "odd m ~ odd (from m)" $ Q.withMaxSuccess 500 odd_correct ] diff --git a/test/Wider.hs b/test/Wider.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE NumericUnderscores #-} @@ -9,8 +10,10 @@ module Wider ( import qualified Data.Choice as C import qualified Data.Word.Wider as W +import qualified GHC.Num.Integer as I import Test.Tasty import qualified Test.Tasty.HUnit as H +import qualified Test.Tasty.QuickCheck as Q overflowing_add_no_carry :: H.Assertion overflowing_add_no_carry = do @@ -140,6 +143,12 @@ sub_mod = do !e = 0x44acf6b7e36c1342c2c5897204fe09504e1e2efb1a900377dbc4e7a6a133ec56 H.assertBool mempty (W.eq_vartime o e) +instance Q.Arbitrary W.Wider where + arbitrary = fmap W.to Q.arbitrary + +odd_correct :: W.Wider -> Bool +odd_correct w = W.odd w == I.integerTestBit (W.from w) 0 + tests :: TestTree tests = testGroup "wider tests" [ H.testCase "overflowing add, no carry" overflowing_add_no_carry @@ -157,5 +166,6 @@ tests = testGroup "wider tests" [ , H.testCase "sqr" sqr , H.testCase "mul" mul , H.testCase "sub_mod" sub_mod + , Q.testProperty "odd w ~ odd (from w)" $ Q.withMaxSuccess 500 odd_correct ]