Add unit tests
This commit is contained in:
parent
992f2f3fa6
commit
f20497ecf3
4 changed files with 41 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -2,6 +2,7 @@ module Lib
|
|||
( LSystem(..)
|
||||
, Instruction(..)
|
||||
, iterateLSystem
|
||||
, instructions
|
||||
, drawLSystem
|
||||
) where
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
main :: IO ()
|
||||
main = putStrLn "Test suite not yet implemented"
|
35
test/Tests.hs
Normal file
35
test/Tests.hs
Normal file
|
@ -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)"
|
||||
[ ]
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue