Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class Arbitrary t where
arbitrary :: Gen t
```

The `Arbitrary` class represents those types whose values can be
The `Arbitrary` class represents those types whose values can be
_randomly-generated_.

`arbitrary` uses the `Gen` monad to express a random generator for
the type `t`. Combinators in the `Test.QuickCheck.Gen`
the type `t`. Combinators in the `Test.QuickCheck.Gen`
module can be used to construct random generators.

#### `CoArbitrary`
Expand Down Expand Up @@ -138,14 +138,42 @@ instance coarbString :: CoArbitrary String
```


#### `arbUnit`

``` purescript
instance arbUnit :: Arbitrary Unit
```


#### `coarbUnit`

``` purescript
instance coarbUnit :: CoArbitrary Unit
```


#### `arbOrdering`

``` purescript
instance arbOrdering :: Arbitrary Ordering
```


#### `coarbOrdering`

``` purescript
instance coarbOrdering :: CoArbitrary Ordering
```


#### `AlphaNumString`

``` purescript
newtype AlphaNumString
= AlphaNumString String
```

A newtype for `String` whose `Arbitrary` instance generated random
A newtype for `String` whose `Arbitrary` instance generated random
alphanumeric strings.

#### `arbAlphaNumString`
Expand Down
27 changes: 23 additions & 4 deletions src/Test/QuickCheck.purs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import qualified Data.String.Unsafe as SU

import Test.QuickCheck.Gen

-- | The `Arbitrary` class represents those types whose values can be
-- | The `Arbitrary` class represents those types whose values can be
-- | _randomly-generated_.
-- |
-- |
-- | `arbitrary` uses the `Gen` monad to express a random generator for
-- | the type `t`. Combinators in the `Test.QuickCheck.Gen`
-- | the type `t`. Combinators in the `Test.QuickCheck.Gen`
-- | module can be used to construct random generators.
class Arbitrary t where
arbitrary :: Gen t
Expand Down Expand Up @@ -100,7 +100,26 @@ instance arbString :: Arbitrary String where
instance coarbString :: CoArbitrary String where
coarbitrary s = coarbitrary $ (S.charCodeAt 0 <$> S.split "" s)

-- | A newtype for `String` whose `Arbitrary` instance generated random
instance arbUnit :: Arbitrary Unit where
arbitrary = return unit

instance coarbUnit :: CoArbitrary Unit where
coarbitrary _ = perturbGen 1

instance arbOrdering :: Arbitrary Ordering where
arbitrary = do
n <- chooseInt 1 3
return $ case n of
1 -> LT
2 -> EQ
3 -> GT

instance coarbOrdering :: CoArbitrary Ordering where
coarbitrary LT = perturbGen 1
coarbitrary EQ = perturbGen 2
coarbitrary GT = perturbGen 3

-- | A newtype for `String` whose `Arbitrary` instance generated random
-- | alphanumeric strings.
newtype AlphaNumString = AlphaNumString String

Expand Down