Skip to content
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

Make tests run in a few seconds #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src-tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import qualified Crypto.Argon2.FFI as FFI
import Data.Bits (shiftL)
import qualified Data.ByteString as BS
import Data.Ix
import Data.Word (Word32)
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.HUnit
Expand All @@ -19,14 +20,15 @@ arbitraryVersion = arbitraryBoundedEnum
arbitraryHashOptions :: Gen HashOptions
arbitraryHashOptions =
do p <- arbitraryWithin 1 4
HashOptions <$> arbitraryWithin FFI.ARGON2_MIN_TIME (min FFI.ARGON2_MAX_TIME 65536)
HashOptions <$> arbitraryWithin FFI.ARGON2_MIN_TIME (min FFI.ARGON2_MAX_TIME (2 ^ 8))
<*> arbitraryWithin (FFI.ARGON2_MIN_MEMORY*p) (FFI.ARGON2_MIN_MEMORY*p*4) -- arbitraryWithin (max (max FFI.ARGON2_MIN_MEMORY (8 * p)) (shiftL p 3)) (min FFI.ARGON2_MAX_MEMORY 512)
<*> pure p
<*> arbitraryVariant
<*> arbitraryVersion
<*> arbitraryWithin FFI.ARGON2_MIN_OUTLEN (min FFI.ARGON2_MAX_OUTLEN 65536)

arbitraryWithin lower upper = arbitrary `suchThat` (inRange (lower,upper))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the properties testing ever worked with this generator.
p <- arbitraryWithin 1 4 would blindly generate Word32 until it a number between 1 and 4 was returned, essentially preventing progress on the suite.

where
arbitraryWithin :: Word32 -> Word32 -> Gen Word32
arbitraryWithin = curry chooseEnum

arbitraryBytes :: Gen BS.ByteString
arbitraryBytes = BS.pack <$> arbitrary
Expand Down