Skip to content

Commit dce2a58

Browse files
committed
Change behavior of chooseInt to include the upper boundary, closes #31
1 parent dc9040d commit dce2a58

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

docs/Test/QuickCheck.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ main = quickCheck \n -> n + 1 > n
2121
#### `QC`
2222

2323
``` purescript
24-
type QC a = forall eff. Eff (console :: CONSOLE, random :: RANDOM, err :: EXCEPTION | eff) a
24+
type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, err :: EXCEPTION | eff) a
2525
```
2626

2727
A type synonym which represents the effects used by the `quickCheck` function.
2828

2929
#### `quickCheck`
3030

3131
``` purescript
32-
quickCheck :: forall prop. (Testable prop) => prop -> QC Unit
32+
quickCheck :: forall eff prop. (Testable prop) => prop -> QC eff Unit
3333
```
3434

3535
Test a property.
@@ -40,7 +40,7 @@ prints the test results to the console.
4040
#### `quickCheck'`
4141

4242
``` purescript
43-
quickCheck' :: forall prop. (Testable prop) => Int -> prop -> QC Unit
43+
quickCheck' :: forall eff prop. (Testable prop) => Int -> prop -> QC eff Unit
4444
```
4545

4646
A variant of the `quickCheck` function which accepts an extra parameter

docs/Test/QuickCheck/Gen.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ with uniform probability.
102102
chooseInt :: Int -> Int -> Gen Int
103103
```
104104

105-
Create a random generator which chooses an integer from a range.
105+
Create a random generator which chooses uniformly distributed
106+
integers from the closed interval `[a, b]`.
106107

107108
#### `oneOf`
108109

src/Test/QuickCheck/Gen.purs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ choose a b = (*) (max - min) >>> (+) min <$> uniform where
8383
min = M.min a b
8484
max = M.max a b
8585

86-
-- | Create a random generator which chooses an integer from a range.
86+
-- | Create a random generator which chooses uniformly distributed
87+
-- | integers from the closed interval `[a, b]`.
8788
chooseInt :: Int -> Int -> Gen Int
8889
chooseInt a b = clamp <$> lcgStep
8990
where
9091
clamp :: Int -> Int
91-
clamp x = case x `mod` (b - a) of
92+
clamp x = case x `mod` (b - a + one) of
9293
r | r >= 0 -> a + r
93-
| otherwise -> b + r
94+
| otherwise -> b + r + one
9495

9596
-- | Create a random generator which selects and executes a random generator from
9697
-- | a non-empty collection of random generators with uniform probability.

0 commit comments

Comments
 (0)