Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warnings #1175

Merged
merged 3 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/TestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 ((*>), (<*))

Expand Down
39 changes: 23 additions & 16 deletions tidal-core/test/TestUtils.hs
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
{-# 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
(VF a) ~== (VF b) = abs (a - b) < 0.000001
_ ~== _ = 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
Expand Down
Loading