Skip to content

Commit ce76b7f

Browse files
authored
Merge pull request #77 from purescript/arbitrary-nonempty-rebase
Rebased Arbitrary instances for NonEmpty
2 parents df88446 + dc6181b commit ce76b7f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
"purescript-arrays": "^4.0.0",
2424
"purescript-console": "^3.0.0",
2525
"purescript-either": "^3.0.0",
26+
"purescript-enums": "^3.0.0",
2627
"purescript-exceptions": "^3.0.0",
2728
"purescript-lists": "^4.0.0",
29+
"purescript-nonempty": "^4.0.0",
30+
"purescript-partial": "^1.2.0",
2831
"purescript-random": "^3.0.0",
2932
"purescript-strings": "^3.0.0",
30-
"purescript-transformers": "^3.0.0",
31-
"purescript-enums": "^3.0.0",
32-
"purescript-partial": "^1.2.0"
33+
"purescript-transformers": "^3.0.0"
3334
}
3435
}

src/Test/QuickCheck/Arbitrary.purs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import Data.Identity (Identity(..))
1414
import Data.Int (toNumber)
1515
import Data.Lazy (Lazy, defer, force)
1616
import Data.List (List)
17+
import Data.List.NonEmpty (NonEmptyList(..))
1718
import Data.Maybe (Maybe(..))
1819
import Data.Newtype (wrap)
20+
import Data.NonEmpty (NonEmpty(..), (:|))
1921
import Data.String (charCodeAt, fromCharArray, split)
2022
import Data.Tuple (Tuple(..))
21-
import Data.NonEmpty ((:|))
2223

2324
import Test.QuickCheck.Gen (Gen, listOf, chooseInt, sized, perturbGen, repeatable, arrayOf, oneOf, uniform)
2425

@@ -144,3 +145,15 @@ instance arbitraryLazy :: Arbitrary a => Arbitrary (Lazy a) where
144145

145146
instance coarbLazy :: Coarbitrary a => Coarbitrary (Lazy a) where
146147
coarbitrary a = coarbitrary (force a)
148+
149+
instance arbNonEmpty :: (Arbitrary (f a), Arbitrary a) => Arbitrary (NonEmpty f a) where
150+
arbitrary = NonEmpty <$> arbitrary <*> arbitrary
151+
152+
instance coarbNonEmpty :: (Coarbitrary (f a), Coarbitrary a) => Coarbitrary (NonEmpty f a) where
153+
coarbitrary (NonEmpty head tail) = coarbitrary head >>> coarbitrary tail
154+
155+
instance arbNonEmptyList :: Arbitrary a => Arbitrary (NonEmptyList a) where
156+
arbitrary = NonEmptyList <$> arbitrary
157+
158+
instance coarbNonEmptyList :: Coarbitrary a => Coarbitrary (NonEmptyList a) where
159+
coarbitrary (NonEmptyList nel) = coarbitrary nel

0 commit comments

Comments
 (0)