Skip to content

Commit 2c20813

Browse files
committed
adds a test for invert_chord and fixes sorting issue
1 parent c707871 commit 2c20813

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

app/server/ruby/lib/sonicpi/lang/western_theory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def chord_invert(notes, shift)
10551055
elsif(shift < 0)
10561056
chord_invert((notes.to_a[0..-2] + [notes.to_a[-1]-12]).sort, shift+1)
10571057
else
1058-
notes.ring
1058+
notes.ring.sort
10591059
end
10601060
end
10611061
doc name: :chord_invert,

app/server/ruby/test/lang/western_theory/test_invert_chord.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def test_inversion_of_basic_major
3838
# edge case
3939
assert_equal(Lang::WesternTheory.chord_invert(Lang::WesternTheory.chord(:C4, "1"), 1), [72].ring)
4040
assert_equal(Lang::WesternTheory.chord_invert(Lang::WesternTheory.chord(:C4, "1"), -1), [48].ring)
41+
42+
# reported ordering issue: https://github.com/sonic-pi-net/sonic-pi/issues/2779
43+
assert_equal(Lang::WesternTheory.chord_invert(Chord.resolve_degree(:i, :C3, :major, 5), 1), [52, 55, 59, 60, 62].ring)
44+
assert_equal(Lang::WesternTheory.chord_invert(Chord.resolve_degree(:i, :C3, :major, 5), 2), [55, 59, 60, 62, 64].ring)
4145
end
4246

4347
end

0 commit comments

Comments
 (0)