Skip to content

Commit

Permalink
Add property tests for lerp
Browse files Browse the repository at this point in the history
To test the fix for #164.
  • Loading branch information
RyanGlScott committed Apr 15, 2024
1 parent e044271 commit 7552d02
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
6 changes: 5 additions & 1 deletion linear.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ test-suite doctests
test-suite test
type: exitcode-stdio-1.0
main-is: Test.hs
other-modules: Unit.Binary
other-modules: Prop.Quaternion
Prop.V3
Unit.Binary
Unit.Plucker
Unit.V
ghc-options: -Wall -threaded
Expand All @@ -141,8 +143,10 @@ test-suite test
deepseq,
test-framework >= 0.8,
test-framework-hunit >= 0.3,
test-framework-quickcheck2 >= 0.3,
HUnit >= 1.2.5,
linear,
QuickCheck >= 2.5,
reflection,
vector
default-language: Haskell2010
Expand Down
28 changes: 28 additions & 0 deletions tests/Prop/Quaternion.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# OPTIONS_GHC -Wno-orphans #-}
module Prop.Quaternion (tests) where

import Linear.Quaternion (Quaternion(..))
import Linear.Epsilon (nearZero)
import Linear.Vector (lerp)
import Test.Framework (Test, testGroup)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.QuickCheck (Arbitrary(..))

import Prop.V3 ()

instance Arbitrary a => Arbitrary (Quaternion a) where
arbitrary = Quaternion <$> arbitrary <*> arbitrary

prop_lerp0 :: Quaternion Double -> Quaternion Double -> Bool
prop_lerp0 a b = nearZero (lerp 0 a b - a)

prop_lerp1 :: Quaternion Double -> Quaternion Double -> Bool
prop_lerp1 a b = nearZero (lerp 1 a b - b)

tests :: [Test]
tests =
[ testGroup "lerp"
[ testProperty "lerp 0 a b == a" prop_lerp0
, testProperty "lerp 1 a b == b" prop_lerp1
]
]
8 changes: 8 additions & 0 deletions tests/Prop/V3.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# OPTIONS_GHC -Wno-orphans #-}
module Prop.V3 () where

import Linear.V3 (V3(..))
import Test.QuickCheck (Arbitrary(..))

instance Arbitrary a => Arbitrary (V3 a) where
arbitrary = V3 <$> arbitrary <*> arbitrary <*> arbitrary
8 changes: 7 additions & 1 deletion tests/Test.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{-# LANGUAGE CPP #-}
module Main (main) where

import Test.Framework (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit

import qualified Prop.Quaternion
import qualified Unit.Binary
import qualified Unit.Plucker
import qualified Unit.V

tests :: [Test]
tests =
[ testGroup "Unit tests"
[ testGroup "Property tests"
[ testGroup "Quaternion" Prop.Quaternion.tests
]
, testGroup "Unit tests"
[ testGroup "Binary" $ hUnitTestToTests Unit.Binary.tests
, testGroup "Plucker" $ hUnitTestToTests Unit.Plucker.tests
, testGroup "V" $ hUnitTestToTests Unit.V.tests
Expand Down

0 comments on commit 7552d02

Please sign in to comment.