次の人を呼び出して(つまりputする)now_servingメソッドをビルドして、フロントから削除する必要があります。もし誰も並んでいなければ、「奉仕するのを待っている人はいない!」と叫ぶべきです。シフトメソッドを使用して配列の最初の要素を取り除こうとすると、私は間違った出力に終わる。ここではRubyのコードは次のとおりです。FIFO Rubyキューアルゴリズムが動作しない
def now_serving(array)
while array.length != 0
array.each do |name|
puts "Currently serving #{name}."
array.shift
end
end
puts "There is nobody waiting to be served!"
end
しかしarray.shiftは一度だけ働いて、どうすればよい私はそれが連続して配列の最初の要素をドロップしてもらいます。ここでRSpecのためのコードは次のとおりです。
describe "#now_serving" do
context "there are no people in line" do
it "should say that the line is empty" do
expect($stdout).to receive(:puts).with("There is nobody waiting to be served!")
now_serving(katz_deli)
end
end
context "there are people in line" do
it "should serve the first person in line and remove them from the queue" do
expect($stdout).to receive(:puts).with("Currently serving Logan.")
now_serving(other_deli)
expect(other_deli).to eq(%w(Avi Spencer))
end
end
end
end
私のバグを修正。 '' '失敗/エラー:now_serving(other_deli) #>受信:予期しない引数を指定して置きます 予想:( "現在、ローガンサービスを提供しています。") は得た:( "現在、アビサービスを提供しています。") - –
@chumakoff何ですか'katz_deli'と' other_deli'ですか?これらはどこから来たのですか? – chumakoff
これはRspecのテストです。 @chumakoff –