-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tests.hs
110 lines (69 loc) · 2.91 KB
/
Tests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module Main where
import Music (FreeAbelian(..), toInterval, intToFa, toPitch, pitchToFa, faInt, faPitch,
AbstractPitch2(..), AbstractInt2(..), AbstractDur2(..))
import FiveLimit (FreeAbelian3(..), JustInt(..),
toIntJ, intJtoFa)
import Shortcuts
import Control.Exception
import Control.Monad
import Test.QuickCheck
import Data.AdditiveGroup
import Data.AffineSpace
import Data.VectorSpace
import Data.Semigroup hiding (Min)
instance Arbitrary FreeAbelian where
arbitrary = liftM2 (::+) restricted restricted where
restricted = choose ((-500), 500)
instance Arbitrary FreeAbelian3 where
arbitrary = liftM3 (\a -> \b -> \c -> FA3 (a,b,c)) restricted restricted restricted where
restricted = choose ((-500), 500)
instance Arbitrary AbstractInt2 where
arbitrary = do a <- arbitrary
return (toInterval a)
instance Arbitrary AbstractPitch2 where
arbitrary = do a <- arbitrary
return (toPitch a)
instance Arbitrary JustInt where
arbitrary = do a <- arbitrary
return (toIntJ a)
-------- Interval tests
intervalAbelian a b = (a ^+^ b) == (b ^+^ a)
negateAdd a = (a ^-^ a) == zeroV
intervals :: Gen AbstractInt2
intervals = arbitrary
intervalsAreAbelian = forAll intervals intervalAbelian
intervalNegationGivesIdentity = forAll intervals negateAdd
intervalTests = (intervalsAreAbelian .&&. intervalNegationGivesIdentity)
-------- Pitch tests
pitches :: Gen AbstractPitch2
pitches = arbitrary
pitchAntiSim a b = (a .-. b) == (-1) *^ (b .-. a)
pitchIntAdd a b = (a .+^ (b .-. a)) == b
pitchDiffIsAntiSim = forAll pitches pitchAntiSim
pitchDiffCorrect = forAll pitches pitchIntAdd
pitchTests = pitchDiffIsAntiSim .&&. pitchDiffCorrect
-------- FreeAbelian internal tests
favalues :: Gen FreeAbelian
favalues = arbitrary
faPreservesPitch = forAll favalues (\f -> (pitchToFa . toPitch) f == f )
faPreservesIntervals = forAll favalues (\f -> (intToFa . toInterval) f == f )
faPreservesPitch' = forAll pitches (\f -> (toPitch . pitchToFa) f == f)
faPreservesIntervals' = forAll intervals (\f -> (toInterval . intToFa) f == f)
faTests = faPreservesPitch .&&. faPreservesIntervals .&&. faPreservesPitch' .&&. faPreservesIntervals'
-------- Tests for particular vales
testComma = (12 *^ _P5) ^-^ (7 *^ _P8) == comma
individualTests = testComma
-------- Just Int / Pitch / FreeAbelian 3 tests
fa3values :: Gen FreeAbelian3
fa3values = arbitrary
justIntervals :: Gen JustInt
justIntervals = arbitrary
fa3PreservesIntervals = forAll fa3values (\f -> (intJtoFa . toIntJ) f == f )
fa3PreservesIntervals' = forAll justIntervals (\f -> (toIntJ . intJtoFa) f == f)
fa3Tests = fa3PreservesIntervals .&&. fa3PreservesIntervals'
-------- Putting it all together
main = quickCheckResult (intervalTests .&&.
pitchTests .&&.
faTests .&&.
fa3Tests .&&.
individualTests)