1
exercism fetch python scale-generator

scale_generator_test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import unittest

from scale_generator import Scale


class ScaleGeneratorTest(unittest.TestCase):

    def test_naming_scale(self):
        chromatic = Scale('c', 'chromatic')
        expected = 'C chromatic'
        actual = chromatic.name
        self.assertEqual(expected, actual)

    def test_chromatic_scale(self):
        chromatic = Scale('C', 'chromatic')
        expected = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#',
                    'B']
        actual = chromatic.pitches
        self.assertEqual(expected, actual)

    def test_another_chromatic_scale(self):
        chromatic = Scale('F', 'chromatic')
        expected = ['F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb',
                    'E']
        actual = chromatic.pitches
        self.assertEqual(expected, actual)

    def test_naming_major_scale(self):
        major = Scale('G', 'major', 'MMmMMMm')
        expected = 'G major'
        actual = major.name
        self.assertEqual(expected, actual)

    def test_major_scale(self):
        major = Scale('C', 'major', 'MMmMMMm')
        expected = ['C', 'D', 'E', 'F', 'G', 'A', 'B']
        actual = major.pitches
        self.assertEqual(expected, actual)

    def test_another_major_scale(self):
        major = Scale('G', 'major', 'MMmMMMm')
        expected = ['G', 'A', 'B', 'C', 'D', 'E', 'F#']
        actual = major.pitches
        self.assertEqual(expected, actual)

    def test_minor_scale(self):
        minor = Scale('f#', 'minor', 'MmMMmMM')
        expected = ['F#', 'G#', 'A', 'B', 'C#', 'D', 'E']
        actual = minor.pitches
        self.assertEqual(expected, actual)

    def test_another_minor_scale(self):
        minor = Scale('bb', 'minor', 'MmMMmMM')
        expected = ['Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab']
        actual = minor.pitches
        self.assertEqual(expected, actual)

    def test_dorian_mode(self):
        dorian = Scale('d', 'dorian', 'MmMMMmM')
        expected = ['D', 'E', 'F', 'G', 'A', 'B', 'C']
        actual = dorian.pitches
        self.assertEqual(expected, actual)

    def test_mixolydian_mode(self):
        mixolydian = Scale('Eb', 'mixolydian', 'MMmMMmM')
        expected = ['Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'Db']
        actual = mixolydian.pitches
        self.assertEqual(expected, actual)

    def test_lydian_mode(self):
        lydian = Scale('a', 'lydian', 'MMMmMMm')
        expected = ['A', 'B', 'C#', 'D#', 'E', 'F#', 'G#']
        actual = lydian.pitches
        self.assertEqual(expected, actual)

    def test_phrygian_mode(self):
        phrygian = Scale('e', 'phrygian', 'mMMMmMM')
        expected = ['E', 'F', 'G', 'A', 'B', 'C', 'D']
        actual = phrygian.pitches
        self.assertEqual(expected, actual)

    def test_locrian_mode(self):
        locrian = Scale('g', 'locrian', 'mMMmMMM')
        expected = ['G', 'Ab', 'Bb', 'C', 'Db', 'Eb', 'F']
        actual = locrian.pitches
        self.assertEqual(expected, actual)

    def test_harmonic_minor(self):
        harmonic_minor = Scale('d', 'harmonic_minor', 'MmMMmAm')
        expected = ['D', 'E', 'F', 'G', 'A', 'Bb', 'Db']
        actual = harmonic_minor.pitches
        self.assertEqual(expected, actual)

    def test_octatonic(self):
        octatonic = Scale('C', 'octatonic', 'MmMmMmMm')
        expected = ['C', 'D', 'D#', 'F', 'F#', 'G#', 'A', 'B']
        actual = octatonic.pitches
        self.assertEqual(expected, actual)

    def test_hexatonic(self):
        hexatonic = Scale('Db', 'hexatonic', 'MMMMMM')
        expected = ['Db', 'Eb', 'F', 'G', 'A', 'B']
        actual = hexatonic.pitches
        self.assertEqual(expected, actual)

    def test_pentatonic(self):
        pentatonic = Scale('A', 'pentatonic', 'MMAMA')
        expected = ['A', 'B', 'C#', 'E', 'F#']
        actual = pentatonic.pitches
        self.assertEqual(expected, actual)

    def test_enigmatic(self):
        enigmatic = Scale('G', 'enigmatic', 'mAMMMmm')
        expected = ['G', 'G#', 'B', 'C#', 'D#', 'F', 'F#']
        actual = enigmatic.pitches
        self.assertEqual(expected, actual)

    def test_brokeninterval(self):
        with self.assertRaises(ValueError):
            Scale('G', 'enigmatic', 'mAMMMmM')


if __name__ == '__main__':
    unittest.main()