Skip to content

An attempt at better documentation for q-d #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Fix bug by increasing size by 1
It's not possible to reproduce the second bug because `mod` operator
in Haskell is implementeed correctly, not like `rem` in C or Erlang.

> (-1) `mod` 2 == 1
  • Loading branch information
abailly committed Mar 29, 2024
commit 07fa9cae4e43d173620fb37ec7056e3f64543c30
8 changes: 5 additions & 3 deletions quickcheck-dynamic/test/Spec/CircularBuffer/Buffer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ instance Eq Buffer where
-- | See 'New'.
newBuffer :: Int -> IO Buffer
newBuffer n =
Buffer n
Buffer size
<$> newIORef 0
<*> newIORef 0
<*> V.new n
<*> V.new size
where
size = n + 1

-- | See 'Put'.
putBuffer :: Int -> Buffer -> IO ()
Expand All @@ -61,4 +63,4 @@ lenBuffer :: Buffer -> IO Int
lenBuffer Buffer{inp, outp, size} = do
i <- readIORef inp
j <- readIORef outp
return $ (i - j) `mod` size
pure $ (i - j) `mod` size
7 changes: 3 additions & 4 deletions quickcheck-dynamic/test/Spec/CircularBuffer/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Control.Monad.Trans (lift)
import Data.Maybe (fromJust)
import GHC.Generics (Generic)
import Spec.CircularBuffer.Buffer (Buffer, getBuffer, lenBuffer, newBuffer, putBuffer)
import Test.QuickCheck (Arbitrary (..), Property, counterexample, getPositive, oneof)
import Test.QuickCheck.DynamicLogic (DL, DynLogicModel (..), action, anyActions_, assert, assertModel, forAllDL, getModelStateDL, monitorDL)
import Test.QuickCheck (Arbitrary (..), Property, getPositive, oneof)
import Test.QuickCheck.DynamicLogic (DL, DynLogicModel (..), forAllDL)
import Test.QuickCheck.Extras (runPropertyStateT)
import Test.QuickCheck.Monadic (monadicIO)
import Test.QuickCheck.Monadic qualified as QC
Expand Down Expand Up @@ -113,5 +113,4 @@ tests :: TestTree
tests =
testGroup
"Circular Buffer"
[ testProperty "implementation respects its model" prop_CircularBuffer
]
[testProperty "implementation respects its model" prop_CircularBuffer]