Skip to content

Commit d464c5c

Browse files
committed
Merge pull request #14 from purescript/simplify
Simplify: revert to pre-'machines' state.
2 parents da3a279 + 62394d4 commit d464c5c

File tree

10 files changed

+363
-1004
lines changed

10 files changed

+363
-1004
lines changed

Gruntfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = function(grunt) {
2+
3+
"use strict";
4+
5+
grunt.initConfig({
6+
7+
libFiles: [
8+
"src/**/*.purs",
9+
"bower_components/purescript-*/src/**/*.purs",
10+
],
11+
12+
clean: ["output"],
13+
14+
pscMake: ["<%=libFiles%>"],
15+
dotPsci: ["<%=libFiles%>"],
16+
docgen: {
17+
readme: {
18+
src: "src/**/*.purs",
19+
dest: "README.md"
20+
}
21+
},
22+
23+
psc: {
24+
options: {
25+
main: "Main",
26+
modules: ["Main"]
27+
},
28+
example: {
29+
src: ["<%=libFiles%>", "examples/Prelude.purs"],
30+
dest: "tmp/Prelude.js"
31+
}
32+
}
33+
});
34+
35+
grunt.loadNpmTasks("grunt-contrib-clean");
36+
grunt.loadNpmTasks("grunt-purescript");
37+
38+
grunt.registerTask("make", ["pscMake", "dotPsci", "docgen"]);
39+
grunt.registerTask("example", ["psc:example"]);
40+
grunt.registerTask("default", ["make"]);
41+
};

README.md

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,12 @@
77
newtype AlphaNumString where
88
AlphaNumString :: String -> AlphaNumString
99

10-
newtype Negative where
11-
Negative :: Number -> Negative
12-
13-
newtype NonZero where
14-
NonZero :: Number -> NonZero
15-
16-
newtype Positive where
17-
Positive :: Number -> Positive
18-
1910
type QC a = forall eff. Eff (err :: Exception, random :: Random, trace :: Trace | eff) a
2011

2112
data Result where
2213
Success :: Result
2314
Failed :: String -> Result
2415

25-
newtype Signum where
26-
Signum :: Number -> Signum
27-
2816

2917
### Type Classes
3018

@@ -46,24 +34,16 @@
4634

4735
instance arbBoolean :: Arbitrary Boolean
4836

49-
instance arbChar :: Arbitrary Char
37+
instance arbChar :: Arbitrary S.Char
5038

5139
instance arbEither :: (Arbitrary a, Arbitrary b) => Arbitrary (Either a b)
5240

5341
instance arbFunction :: (CoArbitrary a, Arbitrary b) => Arbitrary (a -> b)
5442

5543
instance arbMaybe :: (Arbitrary a) => Arbitrary (Maybe a)
5644

57-
instance arbNegative :: Arbitrary Negative
58-
59-
instance arbNonZero :: Arbitrary NonZero
60-
6145
instance arbNumber :: Arbitrary Number
6246

63-
instance arbPositive :: Arbitrary Positive
64-
65-
instance arbSignum :: Arbitrary Signum
66-
6747
instance arbString :: Arbitrary String
6848

6949
instance arbTuple :: (Arbitrary a, Arbitrary b) => Arbitrary (Tuple a b)
@@ -74,32 +54,20 @@
7454

7555
instance coarbBoolean :: CoArbitrary Boolean
7656

77-
instance coarbChar :: CoArbitrary Char
57+
instance coarbChar :: CoArbitrary S.Char
7858

7959
instance coarbEither :: (CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b)
8060

8161
instance coarbFunction :: (Arbitrary a, CoArbitrary b) => CoArbitrary (a -> b)
8262

8363
instance coarbMaybe :: (CoArbitrary a) => CoArbitrary (Maybe a)
8464

85-
instance coarbNegative :: CoArbitrary Negative
86-
87-
instance coarbNonZero :: CoArbitrary NonZero
88-
8965
instance coarbNumber :: CoArbitrary Number
9066

91-
instance coarbPositive :: CoArbitrary Positive
92-
93-
instance coarbSignum :: CoArbitrary Signum
94-
9567
instance coarbString :: CoArbitrary String
9668

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

99-
instance monoidResult :: Monoid Result
100-
101-
instance semigroupResult :: Semigroup Result
102-
10371
instance showResult :: Show Result
10472

10573
instance testableBoolean :: Testable Boolean
@@ -117,15 +85,73 @@
11785

11886
quickCheck' :: forall prop. (Testable prop) => Number -> prop -> QC Unit
11987

120-
quickCheckPure :: forall prop. (Testable prop) => Number -> Seed -> prop -> [Result]
88+
quickCheckPure :: forall prop. (Testable prop) => Number -> Number -> prop -> [Result]
89+
90+
91+
## Module Test.QuickCheck.Gen
92+
93+
### Types
94+
95+
data Gen a
96+
97+
type GenOut a = { value :: a, state :: GenState }
98+
99+
type GenState = { size :: Size, newSeed :: LCG }
100+
101+
type LCG = Number
102+
103+
type Size = Number
104+
105+
106+
### Type Class Instances
107+
108+
instance applicativeGen :: Applicative Gen
109+
110+
instance applyGen :: Apply Gen
111+
112+
instance bindGen :: Bind Gen
113+
114+
instance functorGen :: Functor Gen
115+
116+
instance monadGen :: Monad Gen
117+
118+
119+
### Values
120+
121+
arrayOf :: forall a. Gen a -> Gen [a]
122+
123+
arrayOf1 :: forall a. Gen a -> Gen (Tuple a [a])
124+
125+
choose :: Number -> Number -> Gen Number
126+
127+
chooseInt :: Number -> Number -> Gen Number
128+
129+
elements :: forall a. a -> [a] -> Gen a
130+
131+
evalGen :: forall a. Gen a -> GenState -> a
132+
133+
frequency :: forall a. Tuple Number (Gen a) -> [Tuple Number (Gen a)] -> Gen a
134+
135+
oneOf :: forall a. Gen a -> [Gen a] -> Gen a
136+
137+
perturbGen :: forall a. Number -> Gen a -> Gen a
138+
139+
repeatable :: forall a b. (a -> Gen b) -> Gen (a -> b)
140+
141+
resize :: forall a. Size -> Gen a -> Gen a
142+
143+
runGen :: forall a. Gen a -> GenState -> GenOut a
121144

122-
smallCheck :: forall prop. (Testable prop) => prop -> QC Unit
145+
showSample :: forall r a. (Show a) => Gen a -> Eff (trace :: Trace | r) Unit
123146

124-
smallCheckPure :: forall prop. (Testable prop) => Number -> prop -> [Result]
147+
showSample' :: forall r a. (Show a) => Size -> Gen a -> Eff (trace :: Trace | r) Unit
125148

126-
statCheck :: forall prop. (Testable prop) => Number -> prop -> QC Unit
149+
sized :: forall a. (Size -> Gen a) -> Gen a
127150

128-
statCheckPure :: forall prop. (Testable prop) => Seed -> Number -> prop -> Result
151+
stateful :: forall a. (GenState -> Gen a) -> Gen a
129152

153+
uniform :: Gen Number
130154

155+
variant :: forall a. LCG -> Gen a -> Gen a
131156

157+
vectorOf :: forall a. Number -> Gen a -> Gen [a]

bower.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "purescript-quickcheck",
3-
"version": "0.1.6",
43
"license": "MIT",
54
"authors": [
65
"John A. De Goes <[email protected]> (http://degoes.net)",
@@ -21,11 +20,8 @@
2120
"purescript-random": "~0.1.1",
2221
"purescript-enums": "~0.2.1",
2322
"purescript-exceptions": "~0.2.1",
24-
"purescript-transformers": "~0.2.1",
25-
"purescript-free": "~0.1.3",
26-
"purescript-machines": "~0.1.5",
2723
"purescript-arrays": "~0.2.1",
28-
"purescript-strings": "~0.3.0",
24+
"purescript-strings": "~0.4.0",
2925
"purescript-math": "~0.1.0",
3026
"purescript-tuples": "~0.2.1",
3127
"purescript-either": "~0.1.3",

examples/Prelude.purs

Lines changed: 17 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,30 @@
1-
module PreludeTests where
1+
module Main where
22

33
import Control.Monad.Eff
44
import Data.Eq
55
import Debug.Trace
66
import Test.QuickCheck
7-
import Test.QuickCheck.LCG
8-
import Control.Monad.Trampoline
9-
import Data.Monoid
10-
import Data.Tuple
11-
import Data.Maybe
12-
import Data.Foldable
13-
import qualified Data.Array as Array
14-
import qualified Math as Math
157

16-
between :: forall a. (Ord a) => a -> a -> a -> Boolean
17-
between min max = \n -> n >= min && n <= max
8+
testConst :: Number -> Number -> Number -> Boolean
9+
testConst a b c = const a b == const a c
1810

19-
data Mega = Mega {
20-
arrayOf :: [Number],
21-
arrayOf1 :: [Number],
22-
choose :: Number,
23-
chooseInt :: Number,
24-
collectAll :: [Number],
25-
allInArray :: [Number],
26-
allInRange :: [Number],
27-
dropGen :: [Number],
28-
takeGen :: [Number],
29-
elements :: [String],
30-
extend :: [String],
31-
infinite :: [String],
32-
perms :: [[String]] }
33-
34-
{- TODO: Remaining cases
35-
, frequency
36-
, oneOf
37-
, perturbGen
38-
, repeatable
39-
, resize
40-
, sample
41-
, sample'
42-
, showSample
43-
, showSample'
44-
, sized
45-
, stateful
46-
, suchThat
47-
, suchThatMaybe
48-
, unfoldGen
49-
, uniform
50-
, variant
51-
, vectorOf
52-
-}
53-
54-
data DetABC = DetABC String
55-
56-
runDetABC :: DetABC -> String
57-
runDetABC (DetABC s) = s
58-
59-
instance arbDetABC :: Arbitrary DetABC where
60-
arbitrary = DetABC <$> allInArray ["A", "B", "C"]
61-
62-
data OneToTen = OneToTen Number
63-
64-
runOneToTen :: OneToTen -> Number
65-
runOneToTen (OneToTen n) = n
66-
67-
instance arbOneToTen :: Arbitrary OneToTen where
68-
arbitrary = OneToTen <$> chooseInt 0 10
69-
70-
instance arbMega :: Arbitrary Mega where
71-
arbitrary = do
72-
arrayOf' <- arrayOf (choose 0 10)
73-
arrayOf1' <- arrayOf1 (choose 0 10)
74-
choose' <- choose 0 10
75-
chooseInt' <- chooseInt 0 10
76-
collectAll' <- collectAll mempty (allInArray [0, 1, 2])
77-
allInArray' <- collectAll mempty (allInArray [0, 1, 2])
78-
allInRange' <- collectAll mempty (allInRange 0 10)
79-
dropGen' <- collectAll mempty $ dropGen 2 (allInArray [2, 1, -1])
80-
takeGen' <- collectAll mempty $ takeGen 2 (allInArray [2, 1, -1])
81-
elements' <- arrayOf $ elements "foo" ["bar", "baz"]
82-
extend' <- collectAll mempty $ extend 3 (pure "5")
83-
infinite' <- collectAll mempty $ takeGen 4 (infinite $ pure "foo")
84-
perms' <- collectAll mempty $ perms ["John", "D"]
85-
return $ Mega {
86-
arrayOf: arrayOf',
87-
arrayOf1: (case arrayOf1' of Tuple a as -> a : as),
88-
choose: choose',
89-
chooseInt: chooseInt',
90-
collectAll: collectAll',
91-
allInArray: allInArray',
92-
allInRange: allInRange',
93-
dropGen: dropGen',
94-
takeGen: takeGen',
95-
elements: elements',
96-
extend: extend',
97-
infinite: infinite',
98-
perms: perms' }
99-
100-
verify_gen :: Mega -> Result
101-
verify_gen (Mega m) = fold [
102-
all (between 0 10) m.arrayOf <?> "arrayOf: " ++ show m.arrayOf,
103-
Array.length m.arrayOf1 >= 1 <?> "arrayOf1: " ++ show m.arrayOf1,
104-
between 0 10 m.choose <?> "choose: " ++ show m.choose,
105-
between 0 10 m.chooseInt &&
106-
Math.floor(m.chooseInt) == m.chooseInt <?> "chooseInt: " ++ show m.chooseInt,
107-
m.collectAll == [0, 1, 2] <?> "collectAll: " ++ show m.collectAll,
108-
m.allInArray == [0, 1, 2] <?> "allInArray: " ++ show m.allInArray,
109-
m.allInRange == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] <?> "allInRange: " ++ show m.allInRange,
110-
m.dropGen == [-1] <?> "dropGen: " ++ show m.dropGen,
111-
m.takeGen == [2, 1] <?> "takeGen: " ++ show m.takeGen,
112-
all (flip elem ["foo", "bar", "baz"]) m.elements <?> "elements: " ++ show m.elements,
113-
m.extend == ["5", "5", "5"] <?> "extend: " ++ show m.extend,
114-
m.infinite == ["foo", "foo", "foo", "foo"] <?> "infinite: " ++ show m.infinite,
115-
m.perms == ["John", "D"] : ["D", "John"] : [] <?> "perms: " ++ show m.perms]
11+
mkMessage :: (Number -> Number) -> String
12+
mkMessage f = "Test failed for function ("
13+
++ show (f 0) ++ ", "
14+
++ show (f 1) ++ ", "
15+
++ show (f 2) ++ ")"
11616

11717
main = do
118-
trace "Gen combinators"
119-
quickCheck $ verify_gen
120-
121-
trace "foldGen"
122-
quickCheck $ (runTrampoline $ foldGen (\a b -> Just $ a + b) 1 mempty (allInArray [1, 2, 3])) == 7
18+
Debug.Trace.trace "testConst:"
19+
quickCheck testConst
12320

124-
trace "smallCheck"
125-
smallCheck $ runDetABC >>> (flip elem ["A", "B", "C"])
21+
Debug.Trace.trace "id is a left unit for <<<"
22+
quickCheck $ \f a -> ((id <<< f) (a :: Number) == (f a) :: Number) <?> mkMessage f
12623

127-
trace "Fair distribution of booleans"
128-
statCheck (1/2) $ (==) true
24+
Debug.Trace.trace "Precedence of && and ||:"
25+
quickCheck $ \a b c -> ((a :: Boolean && b) || c) == ((a || c) && (b || c))
12926

130-
trace "Fair distribution of ints"
131-
statCheck (1/11) $ runOneToTen >>> ((==) 1)
27+
Debug.Trace.trace "Test Eq instance for Ref:"
28+
quickCheck $ \a -> (Ref a :: Ref Number) == Ref a
29+
quickCheck $ \a -> not $ (Ref a :: Ref Number /= Ref a)
13230

0 commit comments

Comments
 (0)