Skip to content

Commit

Permalink
Adjust case of Coarbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
garyb committed Apr 19, 2015
1 parent bf2a948 commit f70074f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
34 changes: 17 additions & 17 deletions docs/Test.QuickCheck.Arbitrary.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ _randomly-generated_.
the type `t`. Combinators in the `Test.QuickCheck.Gen`
module can be used to construct random generators.

#### `CoArbitrary`
#### `Coarbitrary`

``` purescript
class CoArbitrary t where
class Coarbitrary t where
coarbitrary :: forall r. t -> Gen r -> Gen r
```

The `CoArbitrary` class represents types which appear on the left of
The `Coarbitrary` class represents types which appear on the left of
an `Arbitrary` function arrow.

To construct an `Arbitrary` instance for the type `a -> b`, we need to
use the input of type `a` to _perturb_ a random generator for `b`. This
is the role of the `coarbitrary` function.

`CoArbitrary` instances can be written using the `perturbGen` function.
`Coarbitrary` instances can be written using the `perturbGen` function.

#### `arbBoolean`

Expand All @@ -42,7 +42,7 @@ instance arbBoolean :: Arbitrary Boolean
#### `coarbBoolean`

``` purescript
instance coarbBoolean :: CoArbitrary Boolean
instance coarbBoolean :: Coarbitrary Boolean
```


Expand All @@ -56,7 +56,7 @@ instance arbNumber :: Arbitrary Number
#### `coarbNumber`

``` purescript
instance coarbNumber :: CoArbitrary Number
instance coarbNumber :: Coarbitrary Number
```


Expand All @@ -70,7 +70,7 @@ instance arbInt :: Arbitrary Int
#### `coarbInt`

``` purescript
instance coarbInt :: CoArbitrary Int
instance coarbInt :: Coarbitrary Int
```


Expand All @@ -84,7 +84,7 @@ instance arbString :: Arbitrary String
#### `coarbString`

``` purescript
instance coarbString :: CoArbitrary String
instance coarbString :: Coarbitrary String
```


Expand All @@ -98,7 +98,7 @@ instance arbChar :: Arbitrary Char
#### `coarbChar`

``` purescript
instance coarbChar :: CoArbitrary Char
instance coarbChar :: Coarbitrary Char
```


Expand All @@ -112,7 +112,7 @@ instance arbUnit :: Arbitrary Unit
#### `coarbUnit`

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


Expand All @@ -126,7 +126,7 @@ instance arbOrdering :: Arbitrary Ordering
#### `coarbOrdering`

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


Expand All @@ -140,21 +140,21 @@ instance arbArray :: (Arbitrary a) => Arbitrary [a]
#### `coarbArray`

``` purescript
instance coarbArray :: (CoArbitrary a) => CoArbitrary [a]
instance coarbArray :: (Coarbitrary a) => Coarbitrary [a]
```


#### `arbFunction`

``` purescript
instance arbFunction :: (CoArbitrary a, Arbitrary b) => Arbitrary (a -> b)
instance arbFunction :: (Coarbitrary a, Arbitrary b) => Arbitrary (a -> b)
```


#### `coarbFunction`

``` purescript
instance coarbFunction :: (Arbitrary a, CoArbitrary b) => CoArbitrary (a -> b)
instance coarbFunction :: (Arbitrary a, Coarbitrary b) => Coarbitrary (a -> b)
```


Expand All @@ -168,7 +168,7 @@ instance arbTuple :: (Arbitrary a, Arbitrary b) => Arbitrary (Tuple a b)
#### `coarbTuple`

``` purescript
instance coarbTuple :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Tuple a b)
instance coarbTuple :: (Coarbitrary a, Coarbitrary b) => Coarbitrary (Tuple a b)
```


Expand All @@ -182,7 +182,7 @@ instance arbMaybe :: (Arbitrary a) => Arbitrary (Maybe a)
#### `coarbMaybe`

``` purescript
instance coarbMaybe :: (CoArbitrary a) => CoArbitrary (Maybe a)
instance coarbMaybe :: (Coarbitrary a) => Coarbitrary (Maybe a)
```


Expand All @@ -196,7 +196,7 @@ instance arbEither :: (Arbitrary a, Arbitrary b) => Arbitrary (Either a b)
#### `coarbEither`

``` purescript
instance coarbEither :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b)
instance coarbEither :: (Coarbitrary a, Coarbitrary b) => Coarbitrary (Either a b)
```


Expand Down
2 changes: 1 addition & 1 deletion docs/Test.QuickCheck.Data.AlphaNumString.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ instance arbAlphaNumString :: Arbitrary AlphaNumString
#### `coarbAlphaNumString`

``` purescript
instance coarbAlphaNumString :: CoArbitrary AlphaNumString
instance coarbAlphaNumString :: Coarbitrary AlphaNumString
```


Expand Down
2 changes: 1 addition & 1 deletion docs/Test.QuickCheck.Data.ApproxNumber.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ instance arbitraryApproxNumber :: Arbitrary ApproxNumber
#### `coarbitraryApproxNumber`

``` purescript
instance coarbitraryApproxNumber :: CoArbitrary ApproxNumber
instance coarbitraryApproxNumber :: Coarbitrary ApproxNumber
```


Expand Down
32 changes: 16 additions & 16 deletions src/Test/QuickCheck/Arbitrary.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,54 @@ import Test.QuickCheck.Gen
class Arbitrary t where
arbitrary :: Gen t

-- | The `CoArbitrary` class represents types which appear on the left of
-- | The `Coarbitrary` class represents types which appear on the left of
-- | an `Arbitrary` function arrow.
-- |
-- | To construct an `Arbitrary` instance for the type `a -> b`, we need to
-- | use the input of type `a` to _perturb_ a random generator for `b`. This
-- | is the role of the `coarbitrary` function.
-- |
-- | `CoArbitrary` instances can be written using the `perturbGen` function.
class CoArbitrary t where
-- | `Coarbitrary` instances can be written using the `perturbGen` function.
class Coarbitrary t where
coarbitrary :: forall r. t -> Gen r -> Gen r

instance arbBoolean :: Arbitrary Boolean where
arbitrary = do
n <- uniform
return $ (n * 2) < 1

instance coarbBoolean :: CoArbitrary Boolean where
instance coarbBoolean :: Coarbitrary Boolean where
coarbitrary true = perturbGen 1
coarbitrary false = perturbGen 2

instance arbNumber :: Arbitrary Number where
arbitrary = uniform

instance coarbNumber :: CoArbitrary Number where
instance coarbNumber :: Coarbitrary Number where
coarbitrary = perturbGen

instance arbInt :: Arbitrary Int where
arbitrary = chooseInt (fromNumber (-1000000)) (fromNumber 1000000)

instance coarbInt :: CoArbitrary Int where
instance coarbInt :: Coarbitrary Int where
coarbitrary = perturbGen <<< toNumber

instance arbString :: Arbitrary String where
arbitrary = fromCharArray <$> arbitrary

instance coarbString :: CoArbitrary String where
instance coarbString :: Coarbitrary String where
coarbitrary s = coarbitrary $ (charCodeAt zero <$> split "" s)

instance arbChar :: Arbitrary Char where
arbitrary = fromCharCode <<< fromNumber <<< (* 65535) <$> uniform

instance coarbChar :: CoArbitrary Char where
instance coarbChar :: Coarbitrary Char where
coarbitrary c = coarbitrary $ toCharCode c

instance arbUnit :: Arbitrary Unit where
arbitrary = return unit

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

instance arbOrdering :: Arbitrary Ordering where
Expand All @@ -76,7 +76,7 @@ instance arbOrdering :: Arbitrary Ordering where
2 -> EQ
3 -> GT

instance coarbOrdering :: CoArbitrary Ordering where
instance coarbOrdering :: Coarbitrary Ordering where
coarbitrary LT = perturbGen 1
coarbitrary EQ = perturbGen 2
coarbitrary GT = perturbGen 3
Expand All @@ -89,30 +89,30 @@ instance arbArray :: (Arbitrary a) => Arbitrary [a] where
as <- arbitrary
return (a : as)

instance coarbArray :: (CoArbitrary a) => CoArbitrary [a] where
instance coarbArray :: (Coarbitrary a) => Coarbitrary [a] where
coarbitrary [] = id
coarbitrary (x : xs) = coarbitrary xs <<< coarbitrary x

instance arbFunction :: (CoArbitrary a, Arbitrary b) => Arbitrary (a -> b) where
instance arbFunction :: (Coarbitrary a, Arbitrary b) => Arbitrary (a -> b) where
arbitrary = repeatable (\a -> coarbitrary a arbitrary)

instance coarbFunction :: (Arbitrary a, CoArbitrary b) => CoArbitrary (a -> b) where
instance coarbFunction :: (Arbitrary a, Coarbitrary b) => Coarbitrary (a -> b) where
coarbitrary f gen = do
xs <- arbitrary
coarbitrary (map f xs) gen

instance arbTuple :: (Arbitrary a, Arbitrary b) => Arbitrary (Tuple a b) where
arbitrary = Tuple <$> arbitrary <*> arbitrary

instance coarbTuple :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Tuple a b) where
instance coarbTuple :: (Coarbitrary a, Coarbitrary b) => Coarbitrary (Tuple a b) where
coarbitrary (Tuple a b) = coarbitrary a >>> coarbitrary b

instance arbMaybe :: (Arbitrary a) => Arbitrary (Maybe a) where
arbitrary = do
b <- arbitrary
if b then pure Nothing else Just <$> arbitrary

instance coarbMaybe :: (CoArbitrary a) => CoArbitrary (Maybe a) where
instance coarbMaybe :: (Coarbitrary a) => Coarbitrary (Maybe a) where
coarbitrary Nothing = perturbGen 1
coarbitrary (Just a) = coarbitrary a

Expand All @@ -121,6 +121,6 @@ instance arbEither :: (Arbitrary a, Arbitrary b) => Arbitrary (Either a b) where
b <- arbitrary
if b then Left <$> arbitrary else Right <$> arbitrary

instance coarbEither :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b) where
instance coarbEither :: (Coarbitrary a, Coarbitrary b) => Coarbitrary (Either a b) where
coarbitrary (Left a) = coarbitrary a
coarbitrary (Right b) = coarbitrary b
2 changes: 1 addition & 1 deletion src/Test/QuickCheck/Data/AlphaNumString.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ instance arbAlphaNumString :: Arbitrary AlphaNumString where
in charAt index chars


instance coarbAlphaNumString :: CoArbitrary AlphaNumString where
instance coarbAlphaNumString :: Coarbitrary AlphaNumString where
coarbitrary (AlphaNumString s) = coarbitrary s
2 changes: 1 addition & 1 deletion src/Test/QuickCheck/Data/ApproxNumber.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ newtype ApproxNumber = ApproxNumber Number
instance arbitraryApproxNumber :: Arbitrary ApproxNumber where
arbitrary = ApproxNumber <$> arbitrary

instance coarbitraryApproxNumber :: CoArbitrary ApproxNumber where
instance coarbitraryApproxNumber :: Coarbitrary ApproxNumber where
coarbitrary (ApproxNumber n) = coarbitrary n

instance eqApproxNumber :: Eq ApproxNumber where
Expand Down

0 comments on commit f70074f

Please sign in to comment.