point-octree-0.5.5.3: tests/PropTests/BoundingBoxTests/BoundingBoxTests.hs
{- |
Module : PropTests.BoundingBoxTests.BoundingBoxTests
Copyright : Copyright (c) 2016 Michael Litchard
License : BSD3
Maintainer : Michael Litchard
Stability : experimental
Portability: not portable
This module provides property tests for Data.Octree.BoundingBox.BoundingBox
-}
module PropTests.BoundingBoxTests.BoundingBoxTests
( propValidateBoxes
, propMatchValuesToBoxes
) where
import Test.Hspec (Spec, describe)
import Test.Hspec.QuickCheck (prop)
import Data.Octree.Internal (Vector3 (..), fromList)
import Data.Octree.BoundingBox.BoundingBox (BBoxConfig, traverseOctreeBB)
import PropTests.Common
import PropTests.BoundingBoxTests.Utilities
import Data.Octree.BoundingBox.Internal (DefInput, DefOutput, DefNodeValue)
propValidateBoxes :: Spec
propValidateBoxes =
describe "prop_validateBoxes" $
prop propMsg prop_validateBoxes
where
propMsg =
"Testing that arbitarily generated bounding boxes are well-formed."
propMatchValuesToBoxes :: Spec
propMatchValuesToBoxes =
describe "prop_matchValuesToBox" $
prop propMsg $
prop_matchValuesToBox testConfig1 testConfig2
where
propMsg =
"Testing that each generated BBox3 maps to correct [(Vector3, Int)]"
-- | validateBoxes takes the list of all bounding boxes of an Octree
-- and determines if they are all well-formed
prop_validateBoxes :: [(Vector3, Int)] -> Bool
prop_validateBoxes l =
let octree' = fromList l
bbxs = map fst $ traverseOctreeBB testConfig1 bbis octree' (Vector3 0 0 0)
in all isBBox bbxs
type TestConfigOne = BBoxConfig DefInput [DefOutput] DefNodeValue
type TestConfigTwo = BBoxConfig AltInput DefOutput DefNodeValue
-- | matchValuesToBox verifies that each BBox3 generated by
-- TestConfigOne maps to the correct key list
prop_matchValuesToBox :: TestConfigOne ->
TestConfigTwo ->
[(Vector3, Int)] ->
Bool
prop_matchValuesToBox config1 config2 l =
let octree' = fromList l
boxCol1 = traverseOctreeBB config1 bbis octree' x
x = Vector3 0 0 0 -- this is never used but needs to be present
xs' = map fst boxCol1
boxCol2 = map (traverseOctreeBB config2 bbis octree') xs'
validate = map (`elem` boxCol1) boxCol2
in and validate