Skip to content

Commit

Permalink
Merge pull request #1175 from tidalcycles/delint2
Browse files Browse the repository at this point in the history
fix warnings
  • Loading branch information
yaxu authored Feb 22, 2025
2 parents 84d4a9f + 4a1d087 commit 02e5e3a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
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

0 comments on commit 02e5e3a

Please sign in to comment.