summaryrefslogtreecommitdiff
path: root/test.hs
blob: 00dee93f8340a11cf69ea098935edc2d82fb0d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

import Test.HUnit
import Text.Parsec.Error

import Thue.Parser
import Fractran.Parser
import Thue.Interpreter
import Fractran.Interpreter
import Fractran.Example




instance Eq Text.Parsec.Error.ParseError



fractranParser0 = TestCase (assertEqual ""
                                        (Right (FractranProgram [] 2))
                                        (parseFractran "2"))

fractranParser1 = TestCase (assertEqual ""
                                        (Right (FractranProgram [] 2))
                                        (parseFractran "2\n"))

fractranParser2 = TestCase (assertEqual ""
                                        (Right (FractranProgram [] 2))
                                        (parseFractran "\n2"))

fractranParser3 = TestCase (assertEqual ""
                                        (Right (FractranProgram [(1,2)] 2))
                                        (parseFractran "2 1/2"))

fractranParser4 = TestCase (assertEqual ""
                                        (Right (FractranProgram [(2,3)] 3))
                                        (parseFractran "3\n \n2/3\n"))



thueParser0 = TestCase (assertEqual ""
                                    (Right (ThueProgram [ThueRule "a" "b"] "a"))
                                    (parseThue "a::=b\n::=\na"))

thueParser1 = TestCase (assertEqual ""
                                    (Right (ThueProgram [] "b"))
                                    (parseThue "::=\nb"))



extractInfix0 = TestCase (assertEqual ""
                                      Nothing
                                      (extractInfix [1,2] [3,4,5]))

extractInfix1 = TestCase (assertEqual ""
                                      (Just ([1,2],[5,6]))
                                      (extractInfix [3,4] [1,2,3,4,5,6]))

extractInfix2 = TestCase (assertEqual ""
                                      (Just ([],[3,4]))
                                      (extractInfix [0,1,2] [0,1,2,3,4]))

extractInfix3 = TestCase (assertEqual ""
                                      (Just ([1],[]))
                                      (extractInfix [2,3] [1,2,3]))

extractInfix4 = TestCase (assertEqual ""
                                      (Just ([],[1]))
                                      (extractInfix [] [1]))

extractInfix5 = TestCase (assertEqual ""
                                      (Just ("before","after"))
                                      (extractInfix "middle" "beforemiddleafter"))



fractranInterpreter0 = TestCase (assertEqual ""
                                             [108,162,243]
                                             (fractran (FractranProgram addition 108)))

fractranInterpreter1 = TestCase (assertEqual ""
                                             [2,15,825,725,1925,2275,425,390,330,290,770,910,170,156,132,116,308,364,68,4]
                                             (take 20 (fractran prime2)))

fractranInterpreter2 = TestCase (assertEqual ""
                                             [5]
                                             (fractran (FractranProgram addition 5)))



main = do
    putStrLn "Fractran Parser"
    runTestTT $ TestList [fractranParser0, fractranParser1, fractranParser2, fractranParser3, fractranParser4]

    putStrLn "\nFractran Interpreter"
    runTestTT $ TestList [fractranInterpreter0, fractranInterpreter1, fractranInterpreter2]
    
    putStrLn "\nThue Parser"
    runTestTT $ TestList [thueParser0, thueParser1]

    putStrLn "\nextractInfix"
    runTestTT $ TestList [extractInfix0, extractInfix1, extractInfix2, extractInfix3, extractInfix4, extractInfix5]