-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
[#281] Move One property tests from 'doctest' to 'hedgehog' #288
Merged
chshersh
merged 2 commits into
master
from
vrom911/281-Move-property-based-tests-from-doctest
May 13, 2020
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,10 +190,13 @@ test-suite relude-test | |
hs-source-dirs: test | ||
main-is: Spec.hs | ||
|
||
other-modules: Test.Relude.Property | ||
other-modules: Test.Relude.Gen | ||
Test.Relude.Container.One | ||
Test.Relude.Property | ||
Test.Relude.Extra.Validation.Property | ||
build-depends: relude | ||
, bytestring | ||
, containers | ||
, text | ||
, hedgehog ^>= 1.0 | ||
|
||
|
@@ -208,7 +211,6 @@ test-suite relude-doctest | |
build-depends: relude | ||
, doctest | ||
, Glob | ||
, QuickCheck | ||
|
||
ghc-options: -threaded | ||
if impl(ghc >= 8.10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this warning supression also can be removed |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
module Test.Relude.Container.One | ||
( oneProps | ||
) where | ||
|
||
import Relude | ||
|
||
import Hedgehog (Gen, Group (..), Property, forAll, property, (===)) | ||
|
||
import Test.Relude.Gen (genInt, genUtf8Text) | ||
|
||
import qualified Data.ByteString as BS | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified Data.ByteString.Short as SBS | ||
import qualified Data.IntSet as IntSet | ||
import qualified Data.Text as T | ||
import qualified Data.Text.Lazy as TL | ||
import qualified Hedgehog.Gen as Gen | ||
import qualified Hedgehog.Range as Range | ||
|
||
|
||
oneProps :: Group | ||
oneProps = Group "'One' typeclass property tests" | ||
[ ( "length (one @[a] x) ≡ 1", oneListProp) | ||
, ( "length (one @(NonEmpty a) x) ≡ 1", oneNonEmptyProp) | ||
, ( "length (one @(Seq a) x) ≡ 1", oneSeqProp) | ||
, ( "length (one @Text x) ≡ 1", oneTextProp) | ||
, ( "length (one @LText x) ≡ 1", oneLTextProp) | ||
, ( "length (one @ByteString x) ≡ 1", oneByteStringProp) | ||
, ( "length (one @LByteString x) ≡ 1", oneLByteStringProp) | ||
, ( "length (one @ShortByteString x) ≡ 1", oneShortByteStringProp) | ||
, ( "length (one @(Map k v) x) ≡ 1", oneMapProp) | ||
, ( "length (one @(HashMap k v) x) ≡ 1", oneHashMapProp) | ||
, ( "length (one @(IntMap v) x) ≡ 1", oneIntMapProp) | ||
, ( "length (one @(Set a) x) ≡ 1", oneSetProp) | ||
, ( "length (one @(HashSet a) x) ≡ 1", oneHashSetProp) | ||
, ( "length (one @(IntSet x) ≡ 1", oneIntSetProp) | ||
] | ||
Comment on lines
+22
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top test names! |
||
|
||
oneListProp :: Property | ||
oneListProp = property $ do | ||
x <- forAll genInt | ||
length (one @[Int] x) === 1 | ||
|
||
oneNonEmptyProp :: Property | ||
oneNonEmptyProp = property $ do | ||
x <- forAll genInt | ||
length (one @(NonEmpty Int) x) === 1 | ||
|
||
oneSeqProp :: Property | ||
oneSeqProp = property $ do | ||
x <- forAll genInt | ||
length (one @(Seq Int) x) === 1 | ||
|
||
oneTextProp :: Property | ||
oneTextProp = property $ do | ||
x <- forAll Gen.unicode | ||
T.length (one @Text x) === 1 | ||
|
||
oneLTextProp :: Property | ||
oneLTextProp = property $ do | ||
x <- forAll Gen.unicode | ||
TL.length (one @LText x) === 1 | ||
|
||
oneByteStringProp :: Property | ||
oneByteStringProp = property $ do | ||
x <- forAll genWord8 | ||
BS.length (one @ByteString x) === 1 | ||
|
||
oneLByteStringProp :: Property | ||
oneLByteStringProp = property $ do | ||
x <- forAll genWord8 | ||
LBS.length (one @LByteString x) === 1 | ||
|
||
oneShortByteStringProp :: Property | ||
oneShortByteStringProp = property $ do | ||
x <- forAll genWord8 | ||
SBS.length (one @ShortByteString x) === 1 | ||
|
||
oneMapProp :: Property | ||
oneMapProp = property $ do | ||
k <- forAll genUtf8Text | ||
v <- forAll genInt | ||
length (one @(Map Text Int) (k, v)) === 1 | ||
|
||
oneHashMapProp :: Property | ||
oneHashMapProp = property $ do | ||
k <- forAll genUtf8Text | ||
v <- forAll genInt | ||
length (one @(HashMap Text Int) (k, v)) === 1 | ||
|
||
oneIntMapProp :: Property | ||
oneIntMapProp = property $ do | ||
k <- forAll genInt | ||
v <- forAll genUtf8Text | ||
length (one @(IntMap Text) (k, v)) === 1 | ||
|
||
oneSetProp :: Property | ||
oneSetProp = property $ do | ||
v <- forAll genUtf8Text | ||
length (one @(Set Text) v) === 1 | ||
|
||
oneHashSetProp :: Property | ||
oneHashSetProp = property $ do | ||
v <- forAll genUtf8Text | ||
length (one @(HashSet Text) v) === 1 | ||
|
||
oneIntSetProp :: Property | ||
oneIntSetProp = property $ do | ||
v <- forAll genInt | ||
IntSet.size (one v) === 1 | ||
|
||
|
||
genWord8 :: Gen Word8 | ||
genWord8 = Gen.word8 Range.constantBounded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Test.Relude.Gen | ||
( genInt | ||
-- * Strings | ||
, genUtf8String | ||
, genUtf8Text | ||
, genUtf8ByteString | ||
-- * Lists | ||
, genIntList | ||
, genBoolList | ||
) where | ||
|
||
import Relude | ||
|
||
import Hedgehog (Gen) | ||
|
||
import qualified Hedgehog.Gen as Gen | ||
import qualified Hedgehog.Range as Range | ||
|
||
|
||
genInt :: Gen Int | ||
genInt = Gen.enumBounded | ||
|
||
genUtf8String :: Gen String | ||
genUtf8String = Gen.string (Range.linear 0 1000) Gen.unicode | ||
|
||
genUtf8Text :: Gen Text | ||
genUtf8Text = Gen.text (Range.linear 0 1000) Gen.unicode | ||
|
||
genUtf8ByteString :: Gen ByteString | ||
genUtf8ByteString = Gen.utf8 (Range.linear 0 1000) Gen.unicode | ||
|
||
genIntList :: Gen [Int] | ||
genIntList = Gen.list (Range.linear 0 1000) Gen.enumBounded | ||
|
||
genBoolList :: Gen [Bool] | ||
genBoolList = Gen.list (Range.linear 0 1000) Gen.bool |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like when the test structure mirrors module structure 💦