1
exercism fetch elixir scale-generator

scale_generator_test.exs

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("scale_generator.exs", __DIR__)
end

ExUnit.start
ExUnit.configure trace: true, exclude: :pending

defmodule ScaleGeneratorTest do
  use ExUnit.Case

  @major_scale_pattern           "MMmMMMm"
  @minor_scale_pattern           "MmMMmMM"
  @dorian_scale_pattern          "MmMMMmM"
  @mixolydian_scale_pattern      "MMmMMmM"
  @lydian_scale_pattern          "MMMmMMm"
  @phrygian_scale_pattern        "mMMMmMM"
  @locrian_scale_pattern         "mMMmMMM"
  @harmonic_minor_scale_pattern  "MmMMmAm"
  @melodic_minor_scale_pattern   "MmMMMMm"
  @octatonic_scale_pattern       "MmMmMmMm"
  @hexatonic_scale_pattern       "MMMMMM"
  @pentatonic_scale_pattern      "MMAMA"
  @enigmatic_scale_pattern       "mAMMMmm"

  describe "step to next note" do
    #@tag :pending
    test "with half-tone interval" do
      assert ScaleGenerator.step(~w(C C# D D# E F F# G G# A A# B), "C", "m") == "C#"
    end

    @tag :pending
    test "with full tone interval" do
      assert ScaleGenerator.step(~w(C C# D D# E F F# G G# A A# B), "C", "M") == "D"
    end

    @tag :pending
    test "with accidental interval" do
      assert ScaleGenerator.step(~w(C C# D D# E F F# G G# A A# B), "C", "A") == "D#"
    end
  end

  describe "generate chromatic scale" do
    @tag :pending
    test "starting with A" do
      assert ScaleGenerator.chromatic_scale("A") == ~w(A A# B C C# D D# E F F# G G# A)
    end

    @tag :pending
    test "starting with C" do
      assert ScaleGenerator.chromatic_scale("C") == ~w(C C# D D# E F F# G G# A A# B C)
    end

    @tag :pending
    test "starting with G" do
      assert ScaleGenerator.chromatic_scale("G") == ~w(G G# A A# B C C# D D# E F F# G)
    end

    @tag :pending
    test "works with with lowercase notes" do
      assert ScaleGenerator.chromatic_scale("f#") == ~w(F# G G# A A# B C C# D D# E F F#)
    end
  end

  describe "generate flat chromatic scale" do
    @tag :pending
    test "starting with A" do
      assert ScaleGenerator.flat_chromatic_scale("A") == ~w(A Bb B C Db D Eb E F Gb G Ab A)
    end

    @tag :pending
    test "starting with C" do
      assert ScaleGenerator.flat_chromatic_scale("C") == ~w(C Db D Eb E F Gb G Ab A Bb B C)
    end

    @tag :pending
    test "starting with G" do
      assert ScaleGenerator.flat_chromatic_scale("G") == ~w(G Ab A Bb B C Db D Eb E F Gb G)
    end

    @tag :pending
    test "works with with lowercase notes" do
      assert ScaleGenerator.flat_chromatic_scale("Gb") == ~w(Gb G Ab A Bb B C Db D Eb E F Gb)
    end
  end

  describe "find chromatic scale for flat tonics" do
    @tag :pending
    test "using F" do
      assert ScaleGenerator.find_chromatic_scale("F") == ~w(F Gb G Ab A Bb B C Db D Eb E F)
    end

    @tag :pending
    test "using Bb" do
      assert ScaleGenerator.find_chromatic_scale("Bb") == ~w(Bb B C Db D Eb E F Gb G Ab A Bb)
    end

    @tag :pending
    test "using Eb" do
      assert ScaleGenerator.find_chromatic_scale("Eb") == ~w(Eb E F Gb G Ab A Bb B C Db D Eb)
    end

    @tag :pending
    test "using Ab" do
      assert ScaleGenerator.find_chromatic_scale("Ab") == ~w(Ab A Bb B C Db D Eb E F Gb G Ab)
    end

    @tag :pending
    test "using Db" do
      assert ScaleGenerator.find_chromatic_scale("Db") == ~w(Db D Eb E F Gb G Ab A Bb B C Db)
    end

    @tag :pending
    test "using Gb" do
      assert ScaleGenerator.find_chromatic_scale("Gb") == ~w(Gb G Ab A Bb B C Db D Eb E F Gb)
    end

    @tag :pending
    test "using d" do
      assert ScaleGenerator.find_chromatic_scale("d") == ~w(D Eb E F Gb G Ab A Bb B C Db D)
    end

    @tag :pending
    test "using g" do
      assert ScaleGenerator.find_chromatic_scale("g") == ~w(G Ab A Bb B C Db D Eb E F Gb  G)
    end

    @tag :pending
    test "using c" do
      assert ScaleGenerator.find_chromatic_scale("c") == ~w(C Db D Eb E F Gb G Ab A Bb B  C)
    end

    @tag :pending
    test "using f" do
      assert ScaleGenerator.find_chromatic_scale("f") == ~w(F Gb G Ab A Bb B C Db D Eb E F)
    end

    @tag :pending
    test "using bb" do
      assert ScaleGenerator.find_chromatic_scale("bb") == ~w(Bb B C Db D Eb E F Gb G Ab A Bb)
    end

    @tag :pending
    test "using eb" do
      assert ScaleGenerator.find_chromatic_scale("eb") == ~w(Eb E F Gb G Ab A Bb B C Db D Eb)
    end
  end

  describe "find chromatic scale for non-flat tonics" do
    @tag :pending
    test "using A" do
      assert ScaleGenerator.find_chromatic_scale("A") == ~w(A A# B C C# D D# E F F# G G# A)
    end

    @tag :pending
    test "using A#" do
      assert ScaleGenerator.find_chromatic_scale("A#") == ~w(A# B C C# D D# E F F# G G# A A#)
    end

    @tag :pending
    test "using B" do
      assert ScaleGenerator.find_chromatic_scale("B") == ~w(B C C# D D# E F F# G G# A A# B)
    end

    @tag :pending
    test "using C" do
      assert ScaleGenerator.find_chromatic_scale("C") == ~w(C C# D D# E F F# G G# A A# B C)
    end

    @tag :pending
    test "using C#" do
      assert ScaleGenerator.find_chromatic_scale("C#") == ~w(C# D D# E F F# G G# A A# B C C#)
    end

    @tag :pending
    test "using D" do
      assert ScaleGenerator.find_chromatic_scale("D") == ~w(D D# E F F# G G# A A# B C C# D)
    end

    @tag :pending
    test "using D#" do
      assert ScaleGenerator.find_chromatic_scale("D#") == ~w(D# E F F# G G# A A# B C C# D D#)
    end

    @tag :pending
    test "using E" do
      assert ScaleGenerator.find_chromatic_scale("E") == ~w(E F F# G G# A A# B C C# D D# E)
    end

    @tag :pending
    test "using F#" do
      assert ScaleGenerator.find_chromatic_scale("F#") == ~w(F# G G# A A# B C C# D D# E F F#)
    end

    @tag :pending
    test "using G" do
      assert ScaleGenerator.find_chromatic_scale("G") == ~w(G G# A A# B C C# D D# E F F# G)
    end

    @tag :pending
    test "using G#" do
      assert ScaleGenerator.find_chromatic_scale("G#") == ~w(G# A A# B C C# D D# E F F# G G#)
    end
  end

  describe "generate scale from tonic and pattern" do
    @tag :pending
    test "C Major scale" do
      assert ScaleGenerator.scale("C", @major_scale_pattern) == ~w(C D E F G A B C)
    end

    @tag :pending
    test "G Major scale" do
      assert ScaleGenerator.scale("G", @major_scale_pattern) == ~w(G A B C D E F# G)
    end

    @tag :pending
    test "f# minor scale" do
      assert ScaleGenerator.scale("f#", @minor_scale_pattern) == ~w(F# G# A B C# D E F#)
    end

    @tag :pending
    test "b flat minor scale" do
      assert ScaleGenerator.scale("bb", @minor_scale_pattern) == ~w(Bb C Db Eb F Gb Ab Bb)
    end

    @tag :pending
    test "D Dorian scale" do
      assert ScaleGenerator.scale("d", @dorian_scale_pattern) == ~w(D E F G A B C D)
    end

    @tag :pending
    test "E flat Mixolydian scale" do
      assert ScaleGenerator.scale("Eb", @mixolydian_scale_pattern) == ~w(Eb F G Ab Bb C Db Eb)
    end

    @tag :pending
    test "a Lydian scale" do
      assert ScaleGenerator.scale("a", @lydian_scale_pattern) == ~w(A B C# D# E F# G# A)
    end

    @tag :pending
    test "e Phrygian scale" do
      assert ScaleGenerator.scale("e", @phrygian_scale_pattern) == ~w(E F G A B C D E)
    end

    @tag :pending
    test "g Locrian scale" do
      assert ScaleGenerator.scale("g", @locrian_scale_pattern) == ~w(G Ab Bb C Db Eb F G)
    end

    @tag :pending
    test "d Harmonic minor scale" do
      assert ScaleGenerator.scale("d", @harmonic_minor_scale_pattern) == ~w(D E F G A Bb Db D)
    end

    @tag :pending
    test "C Melodic minor scale" do
      assert ScaleGenerator.scale("C", @melodic_minor_scale_pattern) == ~w(C D D# F G A B C)
    end

    @tag :pending
    test "C Octatonic scale" do
      assert ScaleGenerator.scale("C", @octatonic_scale_pattern) == ~w(C D D# F F# G# A B C)
    end

    @tag :pending
    test "D flat Hexatonic scale" do
      assert ScaleGenerator.scale("Db", @hexatonic_scale_pattern) == ~w(Db Eb F G A B Db)
    end

    @tag :pending
    test "A Pentatonic scale" do
      assert ScaleGenerator.scale("A", @pentatonic_scale_pattern) == ~w(A B C# E F# A)
    end

    @tag :pending
    test "G Enigmatic scale" do
      assert ScaleGenerator.scale("G", @enigmatic_scale_pattern) == ~w(G G# B C# D# F F# G)
    end
  end
end