2

出力の関数を開発するために使用する例を使用して、テストの開発をスピードアップしようとしています。

入力と出力の 2 つの配列があります。

function(input[0]) == output[0].

ループは機能していますが、最後のインデックスでスタックします。例: input.length = 10 の場合、常に function(input[10]) == output[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

時間の大幅な節約になると思いますし、うまくいくはずですよね?? あなたが私を助けてくれることを願っています。ありがとう

4

1 に答える 1