Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 2d92a14

Browse files
committed
Switch tests to QuickCheck
1 parent d373a85 commit 2d92a14

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"purescript-newtype": "^2.0.0",
2424
"purescript-parsing": "^4.1.0",
2525
"purescript-precise": "^2.0.0",
26-
"purescript-profunctor-lenses": "^3.2.0",
27-
"purescript-strongcheck": "^3.1.0"
26+
"purescript-profunctor-lenses": "^3.2.0"
27+
},
28+
"devDependencies": {
29+
"purescript-quickcheck": "^4.4.0"
2830
}
2931
}

test/Main.purs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ module Test.Main where
33
import Prelude
44

55
import Control.Monad.Eff (Eff)
6+
import Control.Monad.Eff.Console (CONSOLE)
67
import Control.Monad.Eff.Exception (EXCEPTION)
78
import Control.Monad.Eff.Random (RANDOM)
8-
import Control.Monad.Eff.Console (CONSOLE)
9-
109
import Data.Either as E
11-
import Data.Maybe (Maybe(..))
12-
import Data.StrMap as SM
13-
import Data.Tuple (Tuple(..))
1410
import Data.Json.Extended (EJson, arbitraryEJsonOfSize, renderEJson, parseEJson, decodeEJson, encodeEJson)
1511
import Data.Json.Extended as EJ
1612
import Data.Json.Extended.Cursor as EJC
17-
18-
import Test.StrongCheck ((<?>))
19-
import Test.StrongCheck as SC
20-
import Test.StrongCheck.Arbitrary as SCA
21-
13+
import Data.Maybe (Maybe(..))
14+
import Data.StrMap as SM
15+
import Data.Tuple (Tuple(..))
16+
import Test.QuickCheck ((<?>))
17+
import Test.QuickCheck as QC
18+
import Test.QuickCheck.Arbitrary as QCA
2219
import Text.Parsing.Parser as P
2320

2421
type TestEffects =
@@ -29,25 +26,25 @@ type TestEffects =
2926

3027
newtype ArbEJson = ArbEJson EJson
3128

32-
instance arbitraryArbEJsonSCA.Arbitrary ArbEJson where
29+
instance arbitraryArbEJsonQCA.Arbitrary ArbEJson where
3330
arbitrary = map ArbEJson $ arbitraryEJsonOfSize 3
3431

3532
testJsonSerialization Eff TestEffects Unit
3633
testJsonSerialization =
37-
SC.quickCheck' 1000 \(ArbEJson x) → case decodeEJson (encodeEJson x) of
34+
QC.quickCheck' 1000 \(ArbEJson x) → case decodeEJson (encodeEJson x) of
3835
E.Right y →
3936
x == y
4037
<?> "Mismatch:\n" <> renderEJson x <> "\n" <> renderEJson y
4138
E.Left err →
42-
SC.Failed $ "Parse error: " <> err
39+
QC.Failed $ "Parse error: " <> err
4340

4441
testRenderParse Eff TestEffects Unit
4542
testRenderParse =
46-
SC.quickCheck' 1000 \(ArbEJson x) → case P.runParser (renderEJson x) parseEJson of
43+
QC.quickCheck' 1000 \(ArbEJson x) → case P.runParser (renderEJson x) parseEJson of
4744
E.Right y →
4845
x == y <?> "Mismatch:\n" <> renderEJson x <> "\n" <> renderEJson y
4946
E.Left err →
50-
SC.Failed $ "Parse error: " <> show err <> " when parsing:\n\n " <> renderEJson x <> "\n\n"
47+
QC.Failed $ "Parse error: " <> show err <> " when parsing:\n\n " <> renderEJson x <> "\n\n"
5148

5249
testCursorExamples Eff TestEffects Unit
5350
testCursorExamples = do
@@ -104,16 +101,16 @@ testCursorExamples = do
104101
Maybe (Tuple EJC.Cursor EJC.Cursor)
105102
Eff TestEffects Unit
106103
assertMbTplEq x y =
107-
SC.assert
108-
$ SC.assertEq
104+
QC.quickCheck' 1 $
105+
QC.assertEquals
109106
(map (\(Tuple a b) → "Tuple " <> EJC.renderEJsonCursor a <> " " <> EJC.renderEJsonCursor b) x)
110107
(map (\(Tuple a b) → "Tuple " <> EJC.renderEJsonCursor a <> " " <> EJC.renderEJsonCursor b) y)
111108

112109
assertMbEq Maybe EJson Maybe EJson Eff TestEffects Unit
113-
assertMbEq x y = SC.assert $ SC.assertEq (map renderEJson x) (map renderEJson y)
110+
assertMbEq x y = QC.quickCheck' 1 $ QC.assertEquals (map renderEJson x) (map renderEJson y)
114111

115112
assertEq EJson EJson Eff TestEffects Unit
116-
assertEq x y = SC.assert $ x == y <?> msg
113+
assertEq x y = QC.quickCheck' 1 $ x == y <?> msg
117114
where
118115
msg = renderEJson x <> " /= " <> renderEJson y
119116

0 commit comments

Comments
 (0)