From 323b75630d661cd2470f473f52ae3065d56e1188 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 11 Nov 2017 14:40:39 +0000 Subject: [PATCH] Add first unit tests --- orbit.cabal | 6 +++++- test/Spec.hs | 2 -- test/Tests.hs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) delete mode 100644 test/Spec.hs create mode 100644 test/Tests.hs diff --git a/orbit.cabal b/orbit.cabal index 107d3f9..7216b81 100644 --- a/orbit.cabal +++ b/orbit.cabal @@ -34,9 +34,13 @@ executable orbit-exe test-suite orbit-test type: exitcode-stdio-1.0 hs-source-dirs: test - main-is: Spec.hs + main-is: Tests.hs build-depends: base , orbit + , linear + , tasty + , tasty-hunit + , tasty-quickcheck ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 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..5c74d38 --- /dev/null +++ b/test/Tests.hs @@ -0,0 +1,36 @@ +module Main where + +import Test.Tasty +import Test.Tasty.QuickCheck as QC +import Test.Tasty.HUnit + +import Linear.Vector +import Linear.V3 +import Linear.Affine +import Linear.Metric + +import Lib + +main :: IO () +main = do + defaultMain (testGroup "Orbit tests" [unitTests, propertyChecks]) + +unitTests :: TestTree +unitTests = testGroup "Unit tests" + [ testCase "bodyDistance sun earth" + $ bodyDistance sun earth @?= astronomicalUnit + , testCase "bodyDistance earth moon" + $ bodyDistance earth moon @?= 384399e3 + , testCase "selectOctant sun earth" + $ selectOctant (_bodyPosition sun) earth @?= SED + , testCase "subOctree for an Empty Region" + $ let r = Region (P $ V3 0 0 0) (P $ V3 0 0 0) 1 4 + r' = Region (P $ V3 1 1 1) (P $ V3 0 0 0) 1 2 + in + subOctree r NEU @?= Empty r' + ] + +propertyChecks :: TestTree +propertyChecks = testGroup "Property tests (QuickCheck)" + [ + ]