From f20497ecf37f6a1b4f71c0f8eb1c1859500d0be6 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Mon, 15 Jan 2018 23:25:26 +0000 Subject: [PATCH] Add unit tests --- package.yaml | 7 +++++-- src/Lib.hs | 1 + test/Spec.hs | 2 -- test/Tests.hs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) delete mode 100644 test/Spec.hs create mode 100644 test/Tests.hs diff --git a/package.yaml b/package.yaml index 72102fa..a78edf9 100644 --- a/package.yaml +++ b/package.yaml @@ -38,11 +38,14 @@ executables: tests: lsystems-test: - main: Spec.hs - source-dirs: test + main: Tests.hs + source-dirs: [test, app] ghc-options: - -threaded - -rtsopts - -with-rtsopts=-N dependencies: - lsystems + - tasty + - tasty-hunit + - tasty-quickcheck diff --git a/src/Lib.hs b/src/Lib.hs index 9fa6f7b..0522027 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -2,6 +2,7 @@ module Lib ( LSystem(..) , Instruction(..) , iterateLSystem + , instructions , drawLSystem ) where diff --git a/test/Spec.hs b/test/Spec.hs deleted file mode 100644 index cd4753f..0000000 --- a/test/Spec.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" diff --git a/test/Tests.hs b/test/Tests.hs new file mode 100644 index 0000000..52d712a --- /dev/null +++ b/test/Tests.hs @@ -0,0 +1,35 @@ +module Main where + +import Test.Tasty +import Test.Tasty.QuickCheck as QC +import Test.Tasty.HUnit + +import Graphics.Gloss + +import Lib +import Examples + +main :: IO () +main = do + defaultMain (testGroup "L-systems tests" [unitTests, propertyChecks]) + +unitTests :: TestTree +unitTests = testGroup "Unit tests" + [ testCase "iterate gosper once" + $ axiom (iterateLSystem 1 gosper) @?= "A-B--B+A++AA+B-" + , testCase "iterate sierpinski once" + $ axiom (iterateLSystem 1 sierpinski) @?= "A-B+A+B-A-BB-BB" + , testCase "instructions of one iteration of gosper" + $ instructions (iterateLSystem 1 gosper) @?= [Forward,TurnLeft,Forward,TurnLeft,TurnLeft,Forward,TurnRight,Forward,TurnRight,TurnRight,Forward,Forward,TurnRight,Forward,TurnLeft] + , testCase "instructions of one iteration of sierpinski" + $ instructions (iterateLSystem 1 sierpinski) @?= [Forward,TurnLeft,Forward,TurnRight,Forward,TurnRight,Forward,TurnLeft,Forward,TurnLeft,Forward,Forward,TurnLeft,Forward,Forward] + , testCase "draw axiom of gosper" + $ drawLSystem gosper @?= Line [(10.0,0.0),(0.0,0.0)] + , testCase "draw one iteration of gosper" + $ drawLSystem (iterateLSystem 1 gosper) @?= Line [(25.0,-8.660253),(20.0,-17.320507),(10.0,-17.320507),(-4.7683716e-7,-17.320507),(5.0,-8.660254),(15.0,-8.6602545),(10.0,0.0),(0.0,0.0)] + ] + +propertyChecks :: TestTree +propertyChecks = testGroup "Property tests (QuickCheck)" + [ ] +