Skip to content

Commit 7cefd32

Browse files
committed
Merge pull request #10 from jdegoes/ready/cleanup
misc cleanup
2 parents dcdf9ae + cac372c commit 7cefd32

File tree

5 files changed

+80
-16
lines changed

5 files changed

+80
-16
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
Success :: Result
2323
Failed :: String -> Result
2424

25+
newtype Signum where
26+
Signum :: Number -> Signum
27+
2528

2629
### Type Classes
2730

@@ -57,6 +60,8 @@
5760

5861
instance arbPositive :: Arbitrary Positive
5962

63+
instance arbSignum :: Arbitrary Signum
64+
6065
instance arbString :: Arbitrary String
6166

6267
instance arbTuple :: (Arbitrary a, Arbitrary b) => Arbitrary (Tuple a b)
@@ -81,6 +86,8 @@
8186

8287
instance coarbPositive :: CoArbitrary Positive
8388

89+
instance coarbSignum :: CoArbitrary Signum
90+
8491
instance coarbString :: CoArbitrary String
8592

8693
instance coarbTuple :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Tuple a b)

bower.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
"package.json"
1919
],
2020
"dependencies": {
21-
"purescript-random": "*",
22-
"purescript-exceptions": "*",
23-
"purescript-transformers": "*",
24-
"purescript-free": "0.1.3",
25-
"purescript-machines": "0.1.5",
26-
"purescript-arrays": "*",
27-
"purescript-strings": "*",
28-
"purescript-math": "*",
29-
"purescript-tuples": "*",
30-
"purescript-either": "*",
31-
"purescript-maybe": "*",
32-
"purescript-foldable-traversable": "*"
21+
"purescript-random": "~0.1.1",
22+
"purescript-enums": "~0.2.0",
23+
"purescript-exceptions": "~0.2.1",
24+
"purescript-transformers": "~0.2.1",
25+
"purescript-free": "~0.1.3",
26+
"purescript-machines": "~0.1.5",
27+
"purescript-arrays": "~0.2.1",
28+
"purescript-strings": "~0.2.1",
29+
"purescript-math": "~0.1.0",
30+
"purescript-tuples": "~0.2.1",
31+
"purescript-either": "~0.1.3",
32+
"purescript-maybe": "~0.2.1",
33+
"purescript-foldable-traversable": "~0.1.3"
3334
}
3435
}

src/Test/QuickCheck.purs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ module Test.QuickCheck
77
, NonZero(..)
88
, Positive(..)
99
, QC(..)
10+
, arbitrary
11+
, coarbitrary
1012
, quickCheck
1113
, quickCheck'
1214
, quickCheckPure
1315
, Result(..)
16+
, runAlphaNumString
17+
, runNegative
18+
, runNonZero
19+
, runPositive
20+
, runSignum
21+
, Signum(..)
1422
, smallCheck
1523
, smallCheckPure
1624
, statCheck
1725
, statCheckPure
26+
, test
1827
, Testable
1928
) where
2029

@@ -53,6 +62,8 @@ newtype Negative = Negative Number
5362

5463
newtype NonZero = NonZero Number
5564

65+
newtype Signum = Signum Number
66+
5667
type QC a = forall eff. Eff (trace :: Trace, random :: Random, err :: Exception | eff) a
5768

5869
data Result = Success | Failed String
@@ -127,8 +138,18 @@ countSuccesses = countSuccesses' 0
127138
countSuccesses' acc (Success : rest) = countSuccesses' (acc + 1) rest
128139
countSuccesses' acc (_ : rest) = countSuccesses' acc rest
129140

130-
foreign import maxNumber "var maxNumber = Number.MAX_VALUE;" :: Number
131-
foreign import minNumber "var minNumber = Number.MIN_VALUE;" :: Number
141+
maxNumber :: Number
142+
maxNumber = 9007199254740992
143+
144+
runAlphaNumString (AlphaNumString s) = s
145+
146+
runSignum (Signum n) = n
147+
148+
runPositive (Positive n) = n
149+
150+
runNegative (Negative n) = n
151+
152+
runNonZero (NonZero n) = n
132153

133154
instance showResult :: Show Result where
134155
show Success = "Success"
@@ -156,7 +177,7 @@ instance coarbPositive :: CoArbitrary Positive where
156177
coarbitrary (Positive n) = coarbitrary n
157178

158179
instance arbNegative :: Arbitrary Negative where
159-
arbitrary = Negative <$> ((*) minNumber) <$> uniform
180+
arbitrary = Negative <$> ((*) (-maxNumber)) <$> uniform
160181

161182
instance coarbNegative :: CoArbitrary Negative where
162183
coarbitrary (Negative n) = coarbitrary n
@@ -170,6 +191,13 @@ instance arbNonZero :: Arbitrary NonZero where
170191
instance coarbNonZero :: CoArbitrary NonZero where
171192
coarbitrary (NonZero n) = coarbitrary n
172193

194+
instance arbSignum :: Arbitrary Signum where
195+
arbitrary = do b <- arbitrary
196+
return $ Signum (if b then 1 else -1)
197+
198+
instance coarbSignum :: CoArbitrary Signum where
199+
coarbitrary (Signum n) = coarbitrary n
200+
173201
instance arbBoolean :: Arbitrary Boolean where
174202
arbitrary = do
175203
n <- uniform

src/Test/QuickCheck/LCG.purs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Test.QuickCheck.LCG
1919
, foldGen'
2020
, frequency
2121
, infinite
22+
, interleave
2223
, oneOf
2324
, perms
2425
, perturbGen
@@ -249,6 +250,10 @@ extend n (GenT m) = GenT $ loop 0 m
249250

250251
in Mealy.stepMealy st m >>= f
251252

253+
-- | Fairly interleaves two generators.
254+
interleave :: forall f a. (Monad f) => GenT f a -> GenT f a -> GenT f a
255+
interleave (GenT g1) (GenT g2) = GenT $ Mealy.interleave g1 g2
256+
252257
-- | Ensures that a given generator can produce an infinite number of values,
253258
-- | assuming it can produce at least one.
254259
infinite :: forall f a. (Monad f) => GenT f a -> GenT f a
@@ -399,4 +404,4 @@ instance plusGenT :: (Monad f) => Plus (GenT f) where
399404

400405
instance alternativeGenT :: (Monad f) => Alternative (GenT f)
401406

402-
instance monadPlusGenT :: (Monad f) => MonadPlus (GenT f)
407+
instance monadPlusGenT :: (Monad f) => MonadPlus (GenT f)

src/Test/QuickCheck/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787

8888
infinite :: forall f a. (Monad f) => GenT f a -> GenT f a
8989

90+
interleave :: forall f a. (Monad f) => GenT f a -> GenT f a -> GenT f a
91+
9092
oneOf :: forall f a. (Monad f) => GenT f a -> [GenT f a] -> GenT f a
9193

9294
perms :: forall f a. (Monad f) => [a] -> GenT f [a]
@@ -126,4 +128,25 @@
126128
vectorOf :: forall f a. (Monad f) => Number -> GenT f a -> GenT f [a]
127129

128130

131+
## Module Test.QuickCheck.Perturb
132+
133+
### Type Classes
134+
135+
class Perturb a where
136+
perturb :: Number -> a -> Gen a
137+
dist :: a -> a -> Number
138+
139+
140+
### Type Class Instances
141+
142+
instance perturbArray :: (Perturb a) => Perturb [a]
143+
144+
instance perturbNumber :: Perturb Number
145+
146+
instance perturbTuple :: (Perturb a, Perturb b) => Perturb (Tuple a b)
147+
148+
149+
### Values
150+
151+
129152

0 commit comments

Comments
 (0)