-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#281] Move property-based tests from 'doctest' to 'hedgehog' for the…
… 'One' typeclass Resolves #281
- Loading branch information
Showing
5 changed files
with
205 additions
and
45 deletions.
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
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) | ||
] | ||
|
||
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.