Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
t-wallet committed Aug 20, 2024
1 parent c91991d commit d75310a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
2 changes: 1 addition & 1 deletion clash-protocols/src/Data/Constraint/Nat/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cancelMulDiv :: forall a b. (1 <= b) => Dict (DivRU (a * b) b ~ a)
cancelMulDiv = unsafeCoerce (Dict :: Dict (0 ~ 0))

-- | if (1 <= b) then (Mod a b + 1 <= b)
leModulusDivisor :: forall a b. 1 <= b => Dict (Mod a b + 1 <= b)
leModulusDivisor :: forall a b. (1 <= b) => Dict (Mod a b + 1 <= b)
leModulusDivisor = unsafeCoerce (Dict :: Dict (0 <= 0))

-- | if (a <= 0) then (a ~ 0)
Expand Down
4 changes: 2 additions & 2 deletions clash-protocols/src/Protocols/PacketStream/Depacketizers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import Protocols
import qualified Protocols.Df as Df
import Protocols.PacketStream.Base

import Data.Constraint (Dict (Dict))
import Data.Constraint.Nat.Extra (leModulusDivisor, timesDivRu)
import Data.Data ((:~:) (Refl))
import Data.Maybe
import Data.Constraint (Dict(Dict))
import Data.Constraint.Nat.Extra (timesDivRu, leModulusDivisor)

defaultByte :: BitVector 8
defaultByte = 0x00
Expand Down
4 changes: 2 additions & 2 deletions clash-protocols/src/Protocols/PacketStream/Packetizers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import qualified Protocols.Df as Df
import Protocols.PacketStream.Base

import Clash.Sized.Vector.Extra (takeLe)
import Data.Constraint (Dict (Dict))
import Data.Constraint.Nat.Extra (leModulusDivisor, leZeroIsZero, strictlyPositiveDivRu)
import Data.Maybe
import Data.Maybe.Extra
import Data.Constraint.Nat.Extra (leModulusDivisor, strictlyPositiveDivRu, leZeroIsZero)
import Data.Constraint (Dict(Dict))

defaultByte :: BitVector 8
defaultByte = 0x00
Expand Down
89 changes: 45 additions & 44 deletions clash-protocols/tests/Tests/Haxioms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Tests.Haxioms where

import Prelude
import Numeric.Natural
import Prelude

import Hedgehog
import qualified Hedgehog.Gen as Gen
Expand All @@ -14,9 +14,10 @@ import Test.Tasty.Hedgehog (HedgehogTestLimit (HedgehogTestLimit))
import Test.Tasty.Hedgehog.Extra (testProperty)
import Test.Tasty.TH (testGroupGenerator)

-- | Generate a 'Natural' greater than or equal to /n/. Can generate 'Natural's
-- up to /n+1000/. This should be enough, given that naturals in this module are
-- used in proofs.
{- | Generate a 'Natural' greater than or equal to /n/. Can generate 'Natural's
up to /n+1000/. This should be enough, given that naturals in this module are
used in proofs.
-}
genNatural :: Natural -> Gen Natural
genNatural min_ = Gen.integral (Range.linear min_ (1000 + min_))

Expand All @@ -27,64 +28,64 @@ divRU dividend divider =
(n, 0) -> n
(n, _) -> n + 1

-- | Test whether the following equation holds:
--
-- DivRU (a * b) b ~ a
--
-- Given:
--
-- 1 <= b
--
-- Tests: 'Data.Constraint.Nat.Extra.cancelMulDiv'.
--
{- | Test whether the following equation holds:
DivRU (a * b) b ~ a
Given:
1 <= b
Tests: 'Data.Constraint.Nat.Extra.cancelMulDiv'.
-}
prop_cancelMulDiv :: Property
prop_cancelMulDiv = property $ do
a <- forAll (genNatural 0)
b <- forAll (genNatural 1)
divRU (a * b) b === a

-- | Test whether the following equation holds:
--
-- Mod a b + 1 <= b
--
-- Given:
--
-- 1 <= b
--
-- Tests: 'Data.Constraint.Nat.Extra.leModulusDivisor'.
--
{- | Test whether the following equation holds:
Mod a b + 1 <= b
Given:
1 <= b
Tests: 'Data.Constraint.Nat.Extra.leModulusDivisor'.
-}
prop_leModulusDivisor :: Property
prop_leModulusDivisor = property $ do
a <- forAll (genNatural 0)
b <- forAll (genNatural 1)
assert (a `mod` b + 1 <= b)

-- | Test whether the following equation holds:
--
-- 1 <= DivRU a b
--
-- Given:
--
-- 1 <= a, 1 <= b
--
-- Tests: 'Data.Constraint.Nat.Extra.strictlyPositiveDivRu'.
--
{- | Test whether the following equation holds:
1 <= DivRU a b
Given:
1 <= a, 1 <= b
Tests: 'Data.Constraint.Nat.Extra.strictlyPositiveDivRu'.
-}
prop_strictlyPositiveDivRu :: Property
prop_strictlyPositiveDivRu = property $ do
a <- forAll (genNatural 1)
b <- forAll (genNatural 1)
assert (1 <= divRU a b)

-- | Test whether the following equation holds:
--
-- b <= Div (b + (a - 1)) a * a
--
-- Given:
--
-- 1 <= a
--
-- Tests: 'Data.Constraint.Nat.Extra.timesDivRU'.
--
{- | Test whether the following equation holds:
b <= Div (b + (a - 1)) a * a
Given:
1 <= a
Tests: 'Data.Constraint.Nat.Extra.timesDivRU'.
-}
prop_timesDivRU :: Property
prop_timesDivRU = property $ do
a <- forAll (genNatural 1)
Expand Down

0 comments on commit d75310a

Please sign in to comment.