テストがないと何をしているのかわからんよね

id:epsilon_deltaさんの記事
10分でコーディングをやってみた - ボクは算数以外しか出来なかった
を読んでRubyで書いてみた。
zipでやってみます。


できてるっぽいけど、何をやってるのかがわかりにくいなー

require 'rspec'

class Cards

  def self.deal(num_players, deck)

    players = Array.new(num_players){ "" }

    players.zip(*deck.chars.each_slice(num_players).take(deck.size/num_players)).map(&:join)

  end

end

describe Cards do

  describe "#deal" do

    it "ex0" do
      Cards.deal(4, "123123123").should == ["12", "23", "31", "12"]
    end

    it "ex1" do
      Cards.deal(6, "012345012345012345").should == ["000", "111", "222", "333", "444", "555"]
    end

    it "ex2" do
      Cards.deal(4, "111122223333").should == ["123", "123", "123", "123"]
    end

    it "ex3" do
      Cards.deal(1, "012345012345012345").should == ["012345012345012345"]
    end

    it "ex4" do
      Cards.deal(6, "01234").should == ["", "", "", "", "", ""]
    end

    it "ex5" do
      Cards.deal(2, "").should == ["", ""]
    end

  end

end