Skip to content
Open
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
14 changes: 10 additions & 4 deletions chords.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: ee4c89d7bed6b5301ea76804b74ab74db2265473402e362135317ea273e7ff33
-- hash: f837b4f562ba53b2d2f26f2e7af5f96f55ac5c2865d732d975cabd9a52a90dc1

name: chords
version: 0.1.0.0
Expand Down Expand Up @@ -51,8 +51,10 @@ library
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
QuickCheck
, base >=4.7 && <5
, containers
, generic-random
, parsec
default-language: Haskell2010

Expand All @@ -64,9 +66,11 @@ executable chords-exe
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
QuickCheck
, base >=4.7 && <5
, chords
, containers
, generic-random
, parsec
default-language: Haskell2010

Expand All @@ -79,8 +83,10 @@ test-suite chords-test
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
QuickCheck
, base >=4.7 && <5
, chords
, containers
, generic-random
, parsec
default-language: Haskell2010
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies:
- base >= 4.7 && < 5
- containers
- parsec
- generic-random
- QuickCheck

library:
source-dirs: src
Expand Down
10 changes: 9 additions & 1 deletion src/Base/Core/Quality/IQuality.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{-# LANGUAGE DeriveGeneric #-}
module Base.Core.Quality.IQuality
( Quality(..)
, baseQuality
) where

import GHC.Generics
import Generic.Random
import Test.QuickCheck

import Common.Utils (modByFrom)

data Quality
Expand All @@ -11,7 +16,10 @@ data Quality
| Minor
| Diminished Int
| Augmented Int
deriving Show
deriving (Show, Generic)

instance Arbitrary Quality where
arbitrary = genericArbitrary uniform

baseQuality :: Int -> Quality
baseQuality n
Expand Down
22 changes: 20 additions & 2 deletions src/Base/Interval.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DeriveGeneric #-}
module Base.Interval
( Interval
, getQuality
Expand All @@ -9,9 +10,14 @@ module Base.Interval
, jumpIntervalFromNote
, (|+|)
, (|-|)
, propInvertSum
, invert
) where

import GHC.Generics
import Generic.Random
import Test.QuickCheck hiding (getSize)

import Base.Core.Accidental
import Base.Core.Note
import Base.Core.Quality.IQuality
Expand All @@ -24,11 +30,23 @@ import Base.PitchClass

import Common.Utils (modByFrom)

import Data.Maybe (fromJust)
import Data.Maybe (isJust, fromJust)

data Interval = Interval { getQuality :: Quality
, getSize :: Int
}
} deriving (Generic)

-- TODO: change to use a Maybe returning smart constructor when
-- such a thing becomes avalible.
-- The implemention of arbitrary will look something like:
-- suchThatMap
-- (genericArbitrary uniform)
-- (\(size, quality) -> intConstructor size quality)
instance Arbitrary Interval where
arbitrary = suchThat (genericArbitrary uniform) (isJust . intervalToDistance)

propInvertSum :: Interval -> Bool
propInvertSum i = invert i |+| i == intervalFrom Perfect 1

instance Eq Interval where
int1 == int2 = intervalToDistance int1 == intervalToDistance int2
Expand Down