Skip to content
Newer
Older
100644 108 lines (90 sloc) 3.23 KB
e417643 @feuerbach Introduce module hierarchy
authored Jul 3, 2011
1 import Text.Regex.Applicative
2 import Text.Regex.Applicative.Reference
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 2, 2011
3 import Control.Applicative
2483fd3 @feuerbach Test suite
authored Jul 3, 2011
4 import Control.Monad
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
5 import Data.Traversable
b1a396e @feuerbach Add recognition vs parsing tests
authored Jan 8, 2012
6 import Data.Maybe
2483fd3 @feuerbach Test suite
authored Jul 3, 2011
7 import Text.Printf
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
8
a27cf7b @feuerbach Move tests to test-framework
authored Dec 6, 2011
9 import Test.SmallCheck
10 import Test.SmallCheck.Series
11 import Test.Framework
12 import Test.Framework.Providers.SmallCheck
13
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
14 -- Small alphabets as SmallCheck's series
15 newtype A = A { a :: Char } deriving Show
16 instance Serial A where
17 series = cons0 $ A 'a'
18 coseries = error "No coseries, sorry"
19
20 newtype AB = AB { ab :: Char } deriving Show
21 instance Serial AB where
22 series = cons0 (AB 'a') \/ cons0 (AB 'b')
23 coseries = error "No coseries, sorry"
24
25 newtype ABC = ABC { abc :: Char } deriving Show
26 instance Serial ABC where
27 series = cons0 (ABC 'a') \/ cons0 (ABC 'b') \/ cons0 (ABC 'c')
28 coseries = error "No coseries, sorry"
29
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
30 re1 =
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
31 let one = pure 1 <* sym 'a'
32 two = pure 2 <* sym 'a' <* sym 'a'
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
33 in (,) <$> (one <|> two) <*> (two <|> one)
34
35 re2 = sequenceA $
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
36 [ pure 1 <* sym 'a' <* sym 'a' <|>
37 pure 2 <* sym 'a'
38 , pure 3 <* sym 'b'
39 , pure 4 <* sym 'b' <|>
40 pure 5 <* sym 'a' ]
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
41
42 re3 = sequenceA $
43 [ pure 0 <|> pure 1
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
44 , pure 1 <* sym 'a' <* sym 'a' <|>
45 pure 2 <* sym 'a'
46 , pure 3 <* sym 'b' <|> pure 6
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
47 , fmap (+1) $
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
48 pure 4 <* sym 'b' <|>
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
49 pure 7 <|>
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
50 pure 5 <* sym 'a' ]
51
52 re4 = sym 'a' *> many (sym 'b') <* sym 'a'
53
54 re5 = (sym 'a' <|> sym 'a' *> sym 'a') *> many (sym 'a')
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
55
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
56 re6 = many (pure 3 <* sym 'a' <* sym 'a' <* sym 'a' <|> pure 1 <* sym 'a')
e11e41c @feuerbach Add some more tests
authored Jul 2, 2011
57
05b190b @feuerbach Test suite modifications
authored Jul 3, 2011
58 -- Regular expression from the weighted regexp paper.
59 re7 =
60 let many_A_or_B = many (sym 'a' <|> sym 'b')
61 in (,) <$>
62 many ((,,,) <$> many_A_or_B <*> sym 'c' <*> many_A_or_B <*> sym 'c') <*>
63 many_A_or_B
e11e41c @feuerbach Add some more tests
authored Jul 2, 2011
64
75ffb23 @feuerbach Add a test case
authored Jul 4, 2011
65 re8 = (,) <$> many (sym 'a' <|> sym 'b') <*> many (sym 'b' <|> sym 'c')
792fd1a @feuerbach Add another tesT
authored Jul 3, 2011
66
5ce32c2 @feuerbach More tests
authored Jan 8, 2012
67 -- NB: we don't test these against the reference impl, 'cause it will loop!
68 re9 = many (sym 'a' <|> empty) <* sym 'b'
69 re10 = few (sym 'a' <|> empty) <* sym 'b'
70
ec2675d @feuerbach test.hs: no view patterns
authored Feb 11, 2012
71 prop re f s =
72 let fs = map f s in
73 reference re fs == (fs =~ re)
dc78ea1 @feuerbach Some smallcheck tests
authored Jul 1, 2011
74
b1a396e @feuerbach Add recognition vs parsing tests
authored Jan 8, 2012
75 -- Because we have 2 slightly different algorithms for recognition and parsing,
76 -- we test that they agree
77 testRecognitionAgainstParsing re f (map f -> s) =
78 isJust (s =~ re) == isJust (s =~ (re *> pure ()))
79
2483fd3 @feuerbach Test suite
authored Jul 3, 2011
80 tests =
a27cf7b @feuerbach Move tests to test-framework
authored Dec 6, 2011
81 [ testGroup "Engine tests"
034c2fc @feuerbach Tests
authored Dec 6, 2011
82 [ t "re1" 10 $ prop re1 a
83 , t "re2" 10 $ prop re2 ab
84 , t "re3" 10 $ prop re3 ab
85 , t "re4" 10 $ prop re4 ab
86 , t "re5" 10 $ prop re5 a
87 , t "re6" 10 $ prop re6 a
88 , t "re7" 7 $ prop re7 abc
89 , t "re8" 7 $ prop re8 abc
a27cf7b @feuerbach Move tests to test-framework
authored Dec 6, 2011
90 ]
b1a396e @feuerbach Add recognition vs parsing tests
authored Jan 8, 2012
91 , testGroup "Recognition vs parsing"
92 [ t "re1" 10 $ testRecognitionAgainstParsing re1 a
93 , t "re2" 10 $ testRecognitionAgainstParsing re2 ab
94 , t "re3" 10 $ testRecognitionAgainstParsing re3 ab
95 , t "re4" 10 $ testRecognitionAgainstParsing re4 ab
96 , t "re5" 10 $ testRecognitionAgainstParsing re5 a
97 , t "re6" 10 $ testRecognitionAgainstParsing re6 a
98 , t "re7" 7 $ testRecognitionAgainstParsing re7 abc
99 , t "re8" 7 $ testRecognitionAgainstParsing re8 abc
5ce32c2 @feuerbach More tests
authored Jan 8, 2012
100 , t "re8" 10 $ testRecognitionAgainstParsing re9 ab
101 , t "re8" 10 $ testRecognitionAgainstParsing re10 ab
b1a396e @feuerbach Add recognition vs parsing tests
authored Jan 8, 2012
102 ]
a27cf7b @feuerbach Move tests to test-framework
authored Dec 6, 2011
103 ]
034c2fc @feuerbach Tests
authored Dec 6, 2011
104 where
105 t name n = withDepth n . testProperty name
2483fd3 @feuerbach Test suite
authored Jul 3, 2011
106
a27cf7b @feuerbach Move tests to test-framework
authored Dec 6, 2011
107 main = defaultMain tests
Something went wrong with that request. Please try again.