-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
test_pytheory.py
106 lines (80 loc) · 2.41 KB
/
test_pytheory.py
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
import pytest
import pytheory
from pytheory import Tone, TonedScale, Tone, Fretboard, Chord
def test_tone_from_string():
c4 = Tone.from_string("C4")
assert c4.name == "C"
assert c4.octave == 4
def test_tone_initialization():
c4 = Tone(name="C", octave=4)
assert c4.name == "C"
assert c4.octave == 4
def test_tone_addition():
assert (
Tone.from_string("C4", system=pytheory.SYSTEMS["western"]).add(12).full_name
== "C5"
)
def test_tone_subtraction():
assert (
Tone.from_string("C5", system=pytheory.SYSTEMS["western"])
.subtract(12)
.full_name
== "C4"
)
def test_tone_full_name():
c4 = Tone(name="C", octave=4)
d = Tone(name="D", octave=None)
assert c4.full_name == "C4"
assert d.full_name == "D"
def test_tone_system():
c4 = Tone(name="C", octave=4, system="western")
assert c4.system_name == "western"
assert c4.system == pytheory.SYSTEMS["western"]
def test_tone_exists():
c4 = Tone(name="C", octave=4, system="western")
invalid_tone = Tone(name="H", octave=4, system="western")
assert c4.exists == True
assert invalid_tone.exists == False
def test_chord_creation():
c_major = Chord(
tones=[
Tone(name="C", octave=4),
Tone(name="E", octave=4),
Tone(name="G", octave=4),
]
)
assert len(c_major.tones) == 3
assert c_major.tones[0].full_name == "C4"
assert c_major.tones[1].full_name == "E4"
assert c_major.tones[2].full_name == "G4"
def test_chord_harmony():
c_major = Chord(
tones=[
Tone(name="C", octave=4),
Tone(name="E", octave=4),
Tone(name="G", octave=4),
]
)
assert c_major.harmony > 0
def test_chord_dissonance():
c_major = Chord(
tones=[
Tone(name="C", octave=4),
Tone(name="E", octave=4),
Tone(name="G", octave=4),
]
)
assert c_major.dissonance > 0
def test_fretboard_creation():
standard_tuning = [
Tone(name="E", octave=4),
Tone(name="B", octave=3),
Tone(name="G", octave=3),
Tone(name="D", octave=3),
Tone(name="A", octave=2),
Tone(name="E", octave=2),
]
fretboard = Fretboard(tones=standard_tuning)
assert len(fretboard.tones) == 6
assert fretboard.tones[0].full_name == "E4"
assert fretboard.tones[-1].full_name == "E2"