diff --git a/test/TestUtils.hs b/test/TestUtils.hs index 80df8bcf..88684543 100644 --- a/test/TestUtils.hs +++ b/test/TestUtils.hs @@ -5,7 +5,8 @@ module TestUtils where import Data.List (sort) import qualified Data.Map.Strict as Map -import Sound.Tidal.Context +import Sound.Tidal.ParseBP (parseBP_E) +import Sound.Tidal.Pattern ( Arc, ArcF (Arc), Context (Context), @@ -16,10 +17,10 @@ import Sound.Tidal.Context Value (VF, VI, VR, VS), ValueMap, defragParts, - parseBP_E, queryArc, setContext, ) +import Sound.Tidal.Show () import Test.Hspec (Expectation, shouldBe) import Prelude hiding ((*>), (<*)) diff --git a/tidal-core/test/TestUtils.hs b/tidal-core/test/TestUtils.hs index a2aee530..88684543 100644 --- a/tidal-core/test/TestUtils.hs +++ b/tidal-core/test/TestUtils.hs @@ -1,34 +1,38 @@ {-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE InstanceSigs #-} module TestUtils where import Data.List (sort) import qualified Data.Map.Strict as Map -import Data.Ratio as C -import Sound.Tidal.Control as C -import Sound.Tidal.Core as C -import Sound.Tidal.Params as C -import Sound.Tidal.ParseBP as C -import Sound.Tidal.Pattern as C -import Sound.Tidal.Scales as C -import Sound.Tidal.Show as C -import Sound.Tidal.Simple as C -import Sound.Tidal.Stepwise as C -import Sound.Tidal.UI as C -import Prelude hiding ((*>), (<*)) - -import Test.Hspec +import Sound.Tidal.ParseBP (parseBP_E) +import Sound.Tidal.Pattern + ( Arc, + ArcF (Arc), + Context (Context), + ControlPattern, + Event, + EventF (Event, value), + Pattern, + Value (VF, VI, VR, VS), + ValueMap, + defragParts, + queryArc, + setContext, + ) +import Sound.Tidal.Show () +import Test.Hspec (Expectation, shouldBe) import Prelude hiding ((*>), (<*)) class TolerantEq a where (~==) :: a -> a -> Bool instance TolerantEq Double where + (~==) :: Double -> Double -> Bool a ~== b = abs (a - b) < 0.000001 instance TolerantEq Value where + (~==) :: Value -> Value -> Bool (VS a) ~== (VS b) = a == b (VI a) ~== (VI b) = a == b (VR a) ~== (VR b) = a == b @@ -36,12 +40,15 @@ instance TolerantEq Value where _ ~== _ = False instance (TolerantEq a) => TolerantEq [a] where + (~==) :: (TolerantEq a) => [a] -> [a] -> Bool as ~== bs = (length as == length bs) && all (uncurry (~==)) (zip as bs) instance TolerantEq ValueMap where + (~==) :: ValueMap -> ValueMap -> Bool a ~== b = Map.differenceWith (\a' b' -> if a' ~== b' then Nothing else Just a') a b == Map.empty instance TolerantEq (Event ValueMap) where + (~==) :: Event ValueMap -> Event ValueMap -> Bool (Event _ w p x) ~== (Event _ w' p' x') = w == w' && p == p' && x ~== x' -- | Compare the events of two patterns using the given arc