|
| 1 | +#-- |
| 2 | +# This file is part of Sonic Pi: http://sonic-pi.net |
| 3 | +# Full project source: https://github.com/samaaron/sonic-pi |
| 4 | +# License: https://github.com/samaaron/sonic-pi/blob/master/LICENSE.md |
| 5 | +# |
| 6 | +# Copyright 2013, 2014, 2015 by Sam Aaron (http://sam.aaron.name). |
| 7 | +# All rights reserved. |
| 8 | +# |
| 9 | +# Permission is granted for use, copying, modification, and |
| 10 | +# distribution of modified versions of this work as long as this |
| 11 | +# notice is included. |
| 12 | +#++ |
| 13 | + |
| 14 | +require 'test/unit' |
| 15 | +require_relative "../../core" |
| 16 | +require_relative "../lib/sonicpi/chord" |
| 17 | +require_relative "../lib/sonicpi/mods/sound" |
| 18 | + |
| 19 | +module SonicPi |
| 20 | + module Mods |
| 21 | + module Sound |
| 22 | + module_function :invert_chord |
| 23 | + module_function :chord |
| 24 | + end |
| 25 | + end |
| 26 | + class InvertChordTester < Test::Unit::TestCase |
| 27 | + |
| 28 | + def test_inversion_of_basic_major |
| 29 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), 0), [60, 64, 67]) |
| 30 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), 1), [64, 67, 72]) |
| 31 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), 2), [67, 72, 76]) |
| 32 | + |
| 33 | + # what should happen the other way... |
| 34 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), -1).sort, [55, 60, 64]) |
| 35 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), -2).sort, [52, 55, 60]) |
| 36 | + assert_equal(Mods::Sound.invert_chord(Chord.new(:C4, :major), -3).sort, [48, 52, 55]) |
| 37 | + |
| 38 | + # edge case |
| 39 | + assert_equal(Mods::Sound.invert_chord(Mods::Sound.chord(:C4, "1"), 1), [72]) |
| 40 | + assert_equal(Mods::Sound.invert_chord(Mods::Sound.chord(:C4, "1"), -1), [48]) |
| 41 | + end |
| 42 | + |
| 43 | + end |
| 44 | +end |
0 commit comments