Skip to content

Commit 0920044

Browse files
committed
Updates for 0.12
1 parent 2c840b8 commit 0920044

7 files changed

Lines changed: 61 additions & 206 deletions

File tree

bower.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020
"package.json"
2121
],
2222
"dependencies": {
23-
"purescript-arrays": "^4.3.0",
24-
"purescript-console": "^3.0.0",
25-
"purescript-either": "^3.0.0",
26-
"purescript-enums": "^3.0.0",
27-
"purescript-exceptions": "^3.0.0",
28-
"purescript-gen": "^1.0.0",
29-
"purescript-lists": "^4.0.0",
30-
"purescript-nonempty": "^4.0.0",
31-
"purescript-partial": "^1.2.0",
32-
"purescript-random": "^3.0.0",
33-
"purescript-strings": "^3.5.0",
34-
"purescript-transformers": "^3.0.0",
35-
"purescript-generics-rep": "^5.0.0",
36-
"purescript-typelevel-prelude": "^2.4.0",
37-
"purescript-record": "^0.2.0"
23+
"purescript-arrays": "#compiler/0.12",
24+
"purescript-console": "#compiler/0.12",
25+
"purescript-either": "#compiler/0.12",
26+
"purescript-enums": "#compiler/0.12",
27+
"purescript-exceptions": "#compiler/0.12",
28+
"purescript-gen": "#compiler/0.12",
29+
"purescript-generics-rep": "#compiler/0.12",
30+
"purescript-lcg": "#compiler/0.12",
31+
"purescript-lists": "#compiler/0.12",
32+
"purescript-nonempty": "#compiler/0.12",
33+
"purescript-partial": "#compiler/0.12",
34+
"purescript-random": "#compiler/0.12",
35+
"purescript-record": "#compiler/0.12",
36+
"purescript-strings": "#compiler/0.12",
37+
"purescript-transformers": "#compiler/0.12",
38+
"purescript-typelevel-prelude": "#compiler/0.12"
3839
},
3940
"devDependencies": {
40-
"purescript-assert": "^3.0.0"
41+
"purescript-assert": "#compiler/0.12"
4142
}
4243
}

src/Test/QuickCheck.purs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
-- | main = quickCheck \n -> n + 1 > n
1717
-- | ```
1818
module Test.QuickCheck
19-
( QC
20-
, quickCheck
19+
( quickCheck
2120
, quickCheckGen
2221
, quickCheck'
2322
, quickCheckGen'
@@ -44,36 +43,31 @@ module Test.QuickCheck
4443
, (>?)
4544
, assertGreaterThanEq
4645
, (>=?)
47-
, module Test.QuickCheck.LCG
46+
, module Random.LCG
4847
, module Test.QuickCheck.Arbitrary
4948
) where
5049

5150
import Prelude
5251

53-
import Control.Monad.Eff (Eff)
54-
import Control.Monad.Eff.Console (CONSOLE, log)
55-
import Control.Monad.Eff.Exception (EXCEPTION, throwException, error)
56-
import Control.Monad.Eff.Random (RANDOM)
5752
import Control.Monad.Rec.Class (Step(..), tailRec)
5853
import Data.Foldable (for_)
5954
import Data.List (List)
6055
import Data.Maybe (Maybe(..))
6156
import Data.Maybe.First (First(..))
62-
import Data.Monoid (mempty)
6357
import Data.Tuple (Tuple(..))
6458
import Data.Unfoldable (replicateA)
59+
import Effect (Effect)
60+
import Effect.Console (log)
61+
import Effect.Exception (throwException, error)
62+
import Random.LCG (Seed, mkSeed, unSeed, randomSeed)
6563
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary, class Coarbitrary, coarbitrary)
6664
import Test.QuickCheck.Gen (Gen, evalGen, runGen)
67-
import Test.QuickCheck.LCG (Seed, runSeed, randomSeed)
68-
69-
-- | A type synonym which represents the effects used by the `quickCheck` function.
70-
type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, exception :: EXCEPTION | eff) a
7165

7266
-- | Test a property.
7367
-- |
7468
-- | This function generates a new random seed, runs 100 tests and
7569
-- | prints the test results to the console.
76-
quickCheck :: forall eff prop. Testable prop => prop -> QC eff Unit
70+
quickCheck :: forall prop. Testable prop => prop -> Effect Unit
7771
quickCheck prop = quickCheck' 100 prop
7872

7973
-- | A version of `quickCheck` with the property specialized to `Gen`.
@@ -84,31 +78,31 @@ quickCheck prop = quickCheck' 100 prop
8478
-- | `MonadGen`-constrained properties as they will not infer correctly when
8579
-- | used with the `quickCheck` functions unless an explicit type annotation is
8680
-- | used.
87-
quickCheckGen :: forall eff prop. Testable prop => Gen prop -> QC eff Unit
81+
quickCheckGen :: forall prop. Testable prop => Gen prop -> Effect Unit
8882
quickCheckGen = quickCheck
8983

9084
-- | A variant of the `quickCheck` function which accepts an extra parameter
9185
-- | representing the number of tests which should be run.
92-
quickCheck' :: forall eff prop. Testable prop => Int -> prop -> QC eff Unit
86+
quickCheck' :: forall prop. Testable prop => Int -> prop -> Effect Unit
9387
quickCheck' n prop = do
9488
seed <- randomSeed
9589
quickCheckWithSeed seed n prop
9690

9791
-- | A version of `quickCheck'` with the property specialized to `Gen`.
98-
quickCheckGen' :: forall eff prop. Testable prop => Int -> Gen prop -> QC eff Unit
92+
quickCheckGen' :: forall prop. Testable prop => Int -> Gen prop -> Effect Unit
9993
quickCheckGen' = quickCheck'
10094

10195
-- | A variant of the `quickCheck'` function that accepts a specific seed as
10296
-- | well as the number tests that should be run.
10397
quickCheckWithSeed
104-
:: forall eff prop. Testable prop => Seed -> Int -> prop -> QC eff Unit
98+
:: forall prop. Testable prop => Seed -> Int -> prop -> Effect Unit
10599
quickCheckWithSeed initialSeed n prop = do
106100
let result = tailRec loop { seed: initialSeed, index: 0, successes: 0, firstFailure: mempty }
107101
log $ show result.successes <> "/" <> show n <> " test(s) passed."
108102
for_ result.firstFailure \{ index, message, seed: failureSeed } ->
109103
throwException $ error
110104
$ "Test " <> show (index + 1)
111-
<> " (seed " <> show (runSeed failureSeed) <> ") failed: \n"
105+
<> " (seed " <> show (unSeed failureSeed) <> ") failed: \n"
112106
<> message
113107
where
114108
loop :: LoopState -> Step LoopState LoopState
@@ -133,7 +127,7 @@ quickCheckWithSeed initialSeed n prop = do
133127
}
134128

135129
-- | A version of `quickCheckWithSeed` with the property specialized to `Gen`.
136-
quickCheckGenWithSeed :: forall eff prop. Testable prop => Seed -> Int -> Gen prop -> QC eff Unit
130+
quickCheckGenWithSeed :: forall prop. Testable prop => Seed -> Int -> Gen prop -> Effect Unit
137131
quickCheckGenWithSeed = quickCheckWithSeed
138132

139133
type LoopState =

src/Test/QuickCheck/Arbitrary.purs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import Prelude
1515

1616
import Control.Monad.Gen.Class (chooseBool)
1717
import Control.Monad.Gen.Common as MGC
18-
import Control.Monad.ST (pureST)
18+
import Control.Monad.ST as ST
1919
import Data.Array.NonEmpty (NonEmptyArray)
2020
import Data.Array.NonEmpty as NEA
2121
import Data.Array.ST (pushSTArray, unsafeFreeze, unsafeThaw)
2222
import Data.Char (toCharCode, fromCharCode)
2323
import Data.Either (Either(..))
2424
import Data.Foldable (foldl)
25-
import Data.Generic.Rep (class Generic, to, from, NoArguments(..), Sum(..), Product(..), Constructor(..), Argument(..), Rec(..), Field(..))
25+
import Data.Generic.Rep (class Generic, to, from, NoArguments(..), Sum(..), Product(..), Constructor(..), Argument(..))
2626
import Data.Identity (Identity(..))
2727
import Data.Int (toNumber)
2828
import Data.Lazy (Lazy, defer, force)
@@ -31,16 +31,17 @@ import Data.List.NonEmpty (NonEmptyList(..))
3131
import Data.Maybe (Maybe(..), fromJust)
3232
import Data.Newtype (wrap)
3333
import Data.NonEmpty (NonEmpty(..), (:|))
34-
import Data.Record (insert)
34+
import Data.Record as Record
3535
import Data.String (charCodeAt, fromCharArray, split)
3636
import Data.String.NonEmpty (NonEmptyString)
3737
import Data.String.NonEmpty as NES
3838
import Data.Symbol (class IsSymbol, SProxy(..))
3939
import Data.Tuple (Tuple(..))
4040
import Partial.Unsafe (unsafePartial)
41+
import Prim.Row as Row
42+
import Prim.RowList as RL
4143
import Test.QuickCheck.Gen (Gen, arrayOf, chooseInt, elements, listOf, oneOf, perturbGen, repeatable, sized, uniform)
42-
import Type.Prelude (class RowToList)
43-
import Type.Row (kind RowList, class RowLacks, Nil, Cons, RLProxy(..))
44+
import Type.Data.RowList (RLProxy(..))
4445

4546
-- | The `Arbitrary` class represents those types whose values can be
4647
-- | _randomly-generated_.
@@ -117,13 +118,13 @@ instance arbArray :: Arbitrary a => Arbitrary (Array a) where
117118
arbitrary = arrayOf arbitrary
118119

119120
instance coarbArray :: Coarbitrary a => Coarbitrary (Array a) where
120-
coarbitrary = foldl (\f x -> f <<< coarbitrary x) id
121+
coarbitrary = foldl (\f x -> f <<< coarbitrary x) identity
121122

122123
instance arbNonEmptyArray :: Arbitrary a => Arbitrary (NonEmptyArray a) where
123124
arbitrary = do
124125
x <- arbitrary
125126
xs <- arbitrary
126-
pure $ unsafePartial fromJust $ NEA.fromArray $ pureST do
127+
pure $ unsafePartial fromJust $ NEA.fromArray $ ST.run do
127128
mxs <- unsafeThaw xs
128129
_ <- pushSTArray mxs x
129130
unsafeFreeze mxs
@@ -163,7 +164,7 @@ instance arbitraryList :: Arbitrary a => Arbitrary (List a) where
163164
arbitrary = sized \n -> chooseInt zero n >>= flip listOf arbitrary
164165

165166
instance coarbList :: Coarbitrary a => Coarbitrary (List a) where
166-
coarbitrary = foldl (\f x -> f <<< coarbitrary x) id
167+
coarbitrary = foldl (\f x -> f <<< coarbitrary x) identity
167168

168169
instance arbitraryIdentity :: Arbitrary a => Arbitrary (Identity a) where
169170
arbitrary = Identity <$> arbitrary
@@ -193,7 +194,7 @@ instance arbitraryNoArguments :: Arbitrary NoArguments where
193194
arbitrary = pure NoArguments
194195

195196
instance coarbitraryNoArguments :: Coarbitrary NoArguments where
196-
coarbitrary NoArguments = id
197+
coarbitrary NoArguments = identity
197198

198199
-- | To be able to evenly distribute over chains of Sum types we build up
199200
-- | a collection of generators and choose between. Each right component
@@ -232,18 +233,6 @@ instance arbitraryArgument :: Arbitrary a => Arbitrary (Argument a) where
232233
instance coarbitraryArgument :: Coarbitrary a => Coarbitrary (Argument a) where
233234
coarbitrary (Argument a) = coarbitrary a
234235

235-
instance arbitraryRec :: Arbitrary a => Arbitrary (Rec a) where
236-
arbitrary = Rec <$> arbitrary
237-
238-
instance coarbitraryRec :: Coarbitrary a => Coarbitrary (Rec a) where
239-
coarbitrary (Rec a) = coarbitrary a
240-
241-
instance arbitraryField :: Arbitrary a => Arbitrary (Field s a) where
242-
arbitrary = Field <$> arbitrary
243-
244-
instance coarbitraryField :: Coarbitrary a => Coarbitrary (Field s a) where
245-
coarbitrary (Field a) = coarbitrary a
246-
247236
-- | A `Generic` implementation of the `arbitrary` member from the `Arbitrary` type class.
248237
genericArbitrary :: forall a rep. Generic a rep => Arbitrary rep => Gen a
249238
genericArbitrary = to <$> (arbitrary :: Gen rep)
@@ -253,30 +242,27 @@ genericCoarbitrary :: forall a rep. Generic a rep => Coarbitrary rep => a -> Gen
253242
genericCoarbitrary x g = to <$> coarbitrary (from x) (from <$> g)
254243

255244
-- | A helper typeclass to implement `Arbitrary` for records.
256-
class ArbitraryRowList
257-
(list :: RowList)
258-
(row :: # Type)
259-
| list -> row where
245+
class ArbitraryRowList list row | list -> row where
260246
arbitraryRecord :: RLProxy list -> Gen (Record row)
261247

262-
instance arbitraryRowListNil :: ArbitraryRowList Nil () where
248+
instance arbitraryRowListNil :: ArbitraryRowList RL.Nil () where
263249
arbitraryRecord _ = pure {}
264250

265251
instance arbitraryRowListCons ::
266252
( Arbitrary a
267253
, ArbitraryRowList listRest rowRest
268-
, RowLacks key rowRest
269-
, RowCons key a rowRest rowFull
270-
, RowToList rowFull (Cons key a listRest)
254+
, Row.Lacks key rowRest
255+
, Row.Cons key a rowRest rowFull
256+
, RL.RowToList rowFull (RL.Cons key a listRest)
271257
, IsSymbol key
272-
) => ArbitraryRowList (Cons key a listRest) rowFull where
258+
) => ArbitraryRowList (RL.Cons key a listRest) rowFull where
273259
arbitraryRecord _ = do
274260
value <- arbitrary
275261
previous <- arbitraryRecord (RLProxy :: RLProxy listRest)
276-
pure $ insert (SProxy :: SProxy key) value previous
262+
pure $ Record.insert (SProxy :: SProxy key) value previous
277263

278264
instance arbitraryRecordInstance ::
279-
( RowToList row list
265+
( RL.RowToList row list
280266
, ArbitraryRowList list row
281267
) => Arbitrary (Record row) where
282268
arbitrary = arbitraryRecord (RLProxy :: RLProxy list)

src/Test/QuickCheck/Data/AlphaNumString.purs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Test/QuickCheck/Gen.purs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import Prelude
3434

3535
import Control.Alt (class Alt)
3636
import Control.Lazy (class Lazy)
37-
import Control.Monad.Eff (Eff)
38-
import Control.Monad.Eff.Random (RANDOM)
3937
import Control.Monad.Gen.Class (class MonadGen)
4038
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
4139
import Control.Monad.State (State, runState, evalState)
@@ -50,9 +48,10 @@ import Data.Monoid.Additive (Additive(..))
5048
import Data.Newtype (unwrap)
5149
import Data.NonEmpty (NonEmpty, (:|))
5250
import Data.Tuple (Tuple(..), fst, snd)
51+
import Effect (Effect)
5352
import Math ((%))
5453
import Partial.Unsafe (unsafePartial)
55-
import Test.QuickCheck.LCG (Seed, lcgPerturb, lcgN, lcgNext, runSeed, randomSeed)
54+
import Random.LCG (Seed, lcgPerturb, lcgM, lcgNext, unSeed, randomSeed)
5655

5756
-- | Tests are parameterized by the `Size` of the randomly-generated data,
5857
-- | the meaning of which depends on the particular generator used.
@@ -231,23 +230,23 @@ sample :: forall a. Seed -> Size -> Gen a -> Array a
231230
sample seed sz g = evalGen (vectorOf sz g) { newSeed: seed, size: sz }
232231

233232
-- | Sample a random generator, using a randomly generated seed
234-
randomSample' :: forall r a. Size -> Gen a -> Eff (random :: RANDOM | r) (Array a)
233+
randomSample' :: forall a. Size -> Gen a -> Effect (Array a)
235234
randomSample' n g = do
236235
seed <- randomSeed
237236
pure $ sample seed n g
238237

239238
-- | Get a random sample of 10 values
240-
randomSample :: forall r a. Gen a -> Eff (random :: RANDOM | r) (Array a)
239+
randomSample :: forall a. Gen a -> Effect (Array a)
241240
randomSample = randomSample' 10
242241

243242
-- | A random generator which simply outputs the current seed
244243
lcgStep :: Gen Int
245244
lcgStep = Gen $ state f where
246-
f s = Tuple (runSeed s.newSeed) (s { newSeed = lcgNext s.newSeed })
245+
f s = Tuple (unSeed s.newSeed) (s { newSeed = lcgNext s.newSeed })
247246

248247
-- | A random generator which approximates a uniform random variable on `[0, 1]`
249248
uniform :: Gen Number
250-
uniform = (\n -> toNumber n / toNumber lcgN) <$> lcgStep
249+
uniform = (\n -> toNumber n / toNumber lcgM) <$> lcgStep
251250

252251
foreign import float32ToInt32 :: Number -> Int
253252

0 commit comments

Comments
 (0)