summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-18 01:57:23 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-18 01:57:23 +1100
commit0ca67c7536c8ab158c6271d8d72e9786f0e0652b (patch)
tree33860dd4e6863c6f68db73ce14bf16bd358d4e67
parenteecb6118d595caffa169e4ababce30e6b8829088 (diff)
Refactored testcases into separate modules for each language
-rw-r--r--Fractran/Test.hs69
-rw-r--r--Thue/Test.hs68
-rw-r--r--Unlambda/Test.hs81
-rw-r--r--makefile10
-rw-r--r--test.hs156
5 files changed, 233 insertions, 151 deletions
diff --git a/Fractran/Test.hs b/Fractran/Test.hs
new file mode 100644
index 0000000..80f5424
--- /dev/null
+++ b/Fractran/Test.hs
@@ -0,0 +1,69 @@
+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 = TestCase (assertEqual ""
+ (Right (FractranProgram [] 2))
+ (parseFractran "2"))
+
+parser1 = TestCase (assertEqual ""
+ (Right (FractranProgram [] 2))
+ (parseFractran "2\n"))
+
+parser2 = TestCase (assertEqual ""
+ (Right (FractranProgram [] 2))
+ (parseFractran "\n2"))
+
+parser3 = TestCase (assertEqual ""
+ (Right (FractranProgram [(1,2)] 2))
+ (parseFractran "2 1/2"))
+
+parser4 = TestCase (assertEqual ""
+ (Right (FractranProgram [(2,3)] 3))
+ (parseFractran "3\n \n2/3\n"))
+
+
+
+interpreter0 = TestCase (assertEqual ""
+ [108,162,243]
+ (fractran (FractranProgram addition 108)))
+
+interpreter1 = 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)))
+
+interpreter2 = TestCase (assertEqual ""
+ [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)
+
diff --git a/Thue/Test.hs b/Thue/Test.hs
new file mode 100644
index 0000000..2e30f6b
--- /dev/null
+++ b/Thue/Test.hs
@@ -0,0 +1,68 @@
+module Thue.Test (
+ parserTests,
+ extractInfixTests,
+ tests
+ ) where
+
+
+import Test.HUnit
+import Text.Parsec.Error
+import Thue.Parser
+import Thue.Interpreter
+
+
+instance Eq Text.Parsec.Error.ParseError
+
+
+
+
+parser0 = TestCase (assertEqual ""
+ (Right (ThueProgram [ThueRule "a" "b"] "a"))
+ (parseThue "a::=b\n::=\na"))
+
+parser1 = 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"))
+
+
+
+parserTests :: Test
+parserTests = TestList [parser0, parser1]
+
+
+
+extractInfixTests :: Test
+extractInfixTests = TestList [extractInfix0, extractInfix1, extractInfix2, extractInfix3, extractInfix4, extractInfix5]
+
+
+
+tests :: Test
+tests = case (parserTests, extractInfixTests) of
+ (TestList a, TestList b) -> TestList (a ++ b)
+
diff --git a/Unlambda/Test.hs b/Unlambda/Test.hs
new file mode 100644
index 0000000..7d1da1e
--- /dev/null
+++ b/Unlambda/Test.hs
@@ -0,0 +1,81 @@
+module Unlambda.Test (
+ parserTests,
+ tests
+ ) where
+
+
+import Test.HUnit
+import Text.Parsec.Error
+import Unlambda.Types
+import Unlambda.Parser
+import Unlambda.Interpreter
+
+
+instance Eq Text.Parsec.Error.ParseError
+
+
+
+
+parser0 = TestCase (assertEqual ""
+ (Right S)
+ (parseUnlambda "s"))
+
+parser1 = TestCase (assertEqual ""
+ (Right K)
+ (parseUnlambda "k"))
+
+parser2 = TestCase (assertEqual ""
+ (Right I)
+ (parseUnlambda "i"))
+
+parser3 = TestCase (assertEqual ""
+ (Right V)
+ (parseUnlambda "v"))
+
+parser4 = TestCase (assertEqual ""
+ (Right R)
+ (parseUnlambda "r"))
+
+parser5 = TestCase (assertEqual ""
+ (Right D)
+ (parseUnlambda "d"))
+
+parser6 = TestCase (assertEqual ""
+ (Right C)
+ (parseUnlambda "c"))
+
+parser7 = TestCase (assertEqual ""
+ (Right E)
+ (parseUnlambda "e"))
+
+parser8 = TestCase (assertEqual ""
+ (Right (App S K))
+ (parseUnlambda "`sk"))
+
+parser9 = TestCase (assertEqual ""
+ (Right (Dot 'c'))
+ (parseUnlambda ".c"))
+
+parser10 = TestCase (assertEqual ""
+ (Right (Compare '?'))
+ (parseUnlambda "??"))
+
+parser11 = TestCase (assertEqual ""
+ (Right Bar)
+ (parseUnlambda "|"))
+
+parser12 = TestCase (assertEqual ""
+ (Right Reed)
+ (parseUnlambda "@"))
+
+
+
+parserTests :: Test
+parserTests = TestList [parser0, parser1, parser2, parser3, parser4, parser5, parser6, parser7, parser8
+ ,parser9, parser10, parser11, parser12]
+
+
+
+tests :: Test
+tests = parserTests
+
diff --git a/makefile b/makefile
index 9b0cfea..0eb8b14 100644
--- a/makefile
+++ b/makefile
@@ -3,6 +3,8 @@ OUTPUTDIR = bin
EXECUTABLES = ${OUTPUTDIR}/test ${OUTPUTDIR}/fractran ${OUTPUTDIR}/thue ${OUTPUTDIR}/unlambda
+SWITCHES = -XDeriveDataTypeable
+
all: testprog fractranprog thueprog unlambdaprog
@@ -18,14 +20,14 @@ distclean:
testprog:
- ghc -XDeriveDataTypeable --make test.hs -o ${OUTPUTDIR}/test
+ ghc ${SWITCHES} --make test.hs -o ${OUTPUTDIR}/test
fractranprog:
- ghc --make fractran.hs -o ${OUTPUTDIR}/fractran
+ ghc ${SWITCHES} --make fractran.hs -o ${OUTPUTDIR}/fractran
thueprog:
- ghc --make thue.hs -o ${OUTPUTDIR}/thue
+ ghc ${SWITCHES} --make thue.hs -o ${OUTPUTDIR}/thue
unlambdaprog:
- ghc -XDeriveDataTypeable --make unlambda.hs -o ${OUTPUTDIR}/unlambda
+ ghc ${SWITCHES} --make unlambda.hs -o ${OUTPUTDIR}/unlambda
diff --git a/test.hs b/test.hs
index 94f575d..a3c4fac 100644
--- a/test.hs
+++ b/test.hs
@@ -1,163 +1,25 @@
import Test.HUnit
-import Text.Parsec.Error
+import qualified Fractran.Test
+import qualified Thue.Test
+import qualified Unlambda.Test
-import Thue.Parser
-import Fractran.Parser
-import Unlambda.Parser
-import Unlambda.Types
-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"))
-
-
-
-unlambdaParser0 = TestCase (assertEqual ""
- (Right S)
- (parseUnlambda "s"))
-
-unlambdaParser1 = TestCase (assertEqual ""
- (Right K)
- (parseUnlambda "k"))
-
-unlambdaParser2 = TestCase (assertEqual ""
- (Right I)
- (parseUnlambda "i"))
-
-unlambdaParser3 = TestCase (assertEqual ""
- (Right V)
- (parseUnlambda "v"))
-
-unlambdaParser4 = TestCase (assertEqual ""
- (Right R)
- (parseUnlambda "r"))
-
-unlambdaParser5 = TestCase (assertEqual ""
- (Right D)
- (parseUnlambda "d"))
-
-unlambdaParser6 = TestCase (assertEqual ""
- (Right C)
- (parseUnlambda "c"))
-
-unlambdaParser7 = TestCase (assertEqual ""
- (Right E)
- (parseUnlambda "e"))
-
-unlambdaParser8 = TestCase (assertEqual ""
- (Right (App S K))
- (parseUnlambda "`sk"))
-
-unlambdaParser9 = TestCase (assertEqual ""
- (Right (Dot 'c'))
- (parseUnlambda ".c"))
-
-unlambdaParser10 = TestCase (assertEqual ""
- (Right (Compare '?'))
- (parseUnlambda "??"))
-
-unlambdaParser11 = TestCase (assertEqual ""
- (Right Bar)
- (parseUnlambda "|"))
-
-unlambdaParser12 = TestCase (assertEqual ""
- (Right Reed)
- (parseUnlambda "@"))
-
-
-
-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]
+ runTestTT Fractran.Test.parserTests
putStrLn "\nFractran Interpreter"
- runTestTT $ TestList [fractranInterpreter0, fractranInterpreter1, fractranInterpreter2]
-
+ runTestTT Fractran.Test.interpreterTests
+
putStrLn "\nThue Parser"
- runTestTT $ TestList [thueParser0, thueParser1]
+ runTestTT Thue.Test.parserTests
putStrLn "\nextractInfix"
- runTestTT $ TestList [extractInfix0, extractInfix1, extractInfix2, extractInfix3, extractInfix4, extractInfix5]
+ runTestTT Thue.Test.extractInfixTests
putStrLn "\nUnlambda Parser"
- runTestTT $ TestList [unlambdaParser0, unlambdaParser1, unlambdaParser2, unlambdaParser3, unlambdaParser4
- ,unlambdaParser5, unlambdaParser6, unlambdaParser7, unlambdaParser8, unlambdaParser9
- ,unlambdaParser10, unlambdaParser11, unlambdaParser12]
+ runTestTT Unlambda.Test.parserTests