summaryrefslogtreecommitdiff
path: root/src/Fractran/Test.hs
blob: 2b507b18e63b41a0221820ebbad9639a412b1d87 (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
module Fractran.Test (
	parserTests,
	interpreterTests,
	tests
    ) where


import Test.HUnit
import Text.Parsec.Error
import Fractran.Parser
import Fractran.Interpreter
import Fractran.Example


instance Eq Text.Parsec.Error.ParseError




parser0 = (Right (FractranProgram [] 2)) ~=? (parseFractran "2")

parser1 = (Right (FractranProgram [] 2)) ~=? (parseFractran "2\n")

parser2 = (Right (FractranProgram [] 2)) ~=? (parseFractran "\n2")

parser3 = (Right (FractranProgram [(1,2)] 2)) ~=? (parseFractran "2 1/2")

parser4 = (Right (FractranProgram [(2,3)] 3)) ~=? (parseFractran "3\n \n2/3\n")



interpreter0 = [108,162,243] ~=? (fractran (FractranProgram addition 108))

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

interpreter2 = [5] ~=? (fractran (FractranProgram addition 5))



parserTests :: Test
parserTests = TestList [parser0, parser1,parser2, parser3, parser4]



interpreterTests :: Test
interpreterTests = TestList [interpreter0, interpreter1, interpreter2]



tests :: Test
tests = case (parserTests, interpreterTests) of
	(TestList a, TestList b) -> TestList (a ++ b)