我正在尝试使用我用来开发输出中的函数的示例来加快我的测试开发。
我有两个数组:输入和输出。
function(input[0]) == output[0]
.
循环正在工作,但它卡在最后一个索引中。例如:如果 input.length = 10 它总是做函数(输入 [10])== 输出 [10]。
describe "multiple_chords" do
input = ["A7 DMaj79", "E-7 A7", "D-7 G7", "Bb-7b5 Eb7b9" , "Bb-7b5 Eb7", "G7 A7", "D-7b5 G7b9", "D-79 G#7913"]
output = [[{"root"=>"A", "def"=>"7"}, {"root"=>"D", "def"=>"Maj7"}], [{"root"=>"E", "def"=>"-7"}, {"root"=>"A", "def"=>"7"}], [{"root"=>"D", "def"=>"-7"}, {"root"=>"G", "def"=>"7"}], [{"root"=>"Bb", "def"=>"-7b5"}, {"root"=>"Eb", "tensions"=>"b9", "def"=>"7"}], [{"root"=>"Bb", "def"=>"-7b5"}, {"root"=>"Eb", "def"=>"7"}], [{"root"=>"G", "def"=>"7"}, {"root"=>"A", "def"=>"7"}], [{"root"=>"D", "def"=>"-7b5"}, {"root"=>"G", "tensions"=>"b9", "def"=>"7"}], [{"root"=>"D", "tensions"=>"9", "def"=>"-7"}, {"root"=>"G#", "tensions"=>["9", "13"], "def"=>"7"}]]
for i in 0..input.length-1
it "analyzes correctly #{input[i]}" do
expect(IpmChords::multiple_chords(input[i])).to eq(output[i])
end
end
end
控制台中的输出是:
6) IpmChords multiple_chords analyzes correctly Bb-7b5 Eb7
Failure/Error: expect(IpmChords::multiple_chords(input[i])).to eq(output[i])
expected: [{"root"=>"D", "tensions"=>"9", "def"=>"-7"}, {"root"=>"G#", "tensions"=>["9", "13"], "def"=>"7"}]
got: [{"root"=>"D", "tensions"=>"9", "def"=>"-7"}, {"root"=>"G#", "tensions"=>"13", "def"=>""}]
(compared using ==)
Diff:
@@ -1,3 +1,3 @@
[{"root"=>"D", "tensions"=>"9", "def"=>"-7"},
- {"root"=>"G#", "tensions"=>["9", "13"], "def"=>"7"}]
+ {"root"=>"G#", "tensions"=>"13", "def"=>""}]
# ./spec/ipm_classes/ipm_chords_ipm_class_spec.rb:28:in `block (4 levels) in <top (required)>'
7) IpmChords multiple_chords analyzes correctly E-7 A7
Failure/Error: expect(IpmChords::multiple_chords(input[i])).to eq(output[i])
expected: [{"root"=>"D", "tensions"=>"9", "def"=>"-7"}, {"root"=>"G#", "tensions"=>["9", "13"], "def"=>"7"}]
got: [{"root"=>"D", "tensions"=>"9", "def"=>"-7"}, {"root"=>"G#", "tensions"=>"13", "def"=>""}]
(compared using ==)
Diff:
@@ -1,3 +1,3 @@
[{"root"=>"D", "tensions"=>"9", "def"=>"-7"},
- {"root"=>"G#", "tensions"=>["9", "13"], "def"=>"7"}]
+ {"root"=>"G#", "tensions"=>"13", "def"=>""}]
你可以看到它总是在计算相同的数组索引,但是每次循环迭代的测试名称都在改变:
6) IpmChords multiple_chords analyzes correctly Bb-7b5 Eb7
7) IpmChords multiple_chords analyzes correctly E-7 A7
我认为这将是一个很好的节省时间,它应该工作,不是吗?希望您能够帮助我。谢谢