require 'spec_helper' describe Array do describe "#delete_first" do it "to be [2, 3]" do expect([1, 2, 3].delete_first).to eq([2, 3]) end end describe "#delete_last" do it "to be [1, 2]" do expect([1, 2, 3].delete_last).to eq([1, 2]) end end describe "#from" do it "to be [1, 2, 3]" do expect([1, 2, 3].from(0)).to eq([1, 2, 3]) end it "to be [2, 3]" do expect([1, 2, 3].from(1)).to eq([2, 3]) end it "to be [3]" do expect([1, 2, 3].from(-1)).to eq([3]) end end describe "#groups" do it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10']]" do expect(%w(1 2 3 4 5 6 7 8 9 10).groups(3)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]]) end end describe "#in_groups" do it "to be [['1', '2', '3', '4'], ['5', '6', '7', nil], ['8', '9', '10', nil]]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3)).to eq([["1", "2", "3", "4"], ["5", "6", "7", nil], ["8", "9", "10", nil]]) end it "to be [['1', '2', '3', '4'], ['5', '6', '7', ' '], ['8', '9', '10', ' ']]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, ' ')).to eq([["1", "2", "3", "4"], ["5", "6", "7", ' '], ["8", "9", "10", " "]]) end it "to be [['1', '2', '3', '4'], ['5', '6', '7'], ['8', '9', '10']]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, false)).to eq([["1", "2", "3", "4"], ["5", "6", "7"], ["8", "9", "10"]]) end end describe "#in_groups_of" do it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10', nil, nil]]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10", nil, nil]]) end it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10', ' ', ' ']]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, ' ')).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10", " ", " "]]) end it "to be [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'] ['10']]" do expect(%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, false)).to eq([["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["10"]]) end end describe "#split" do it "to be [[1, 2], [4, 5]]" do expect([1, 2, 3, 4, 5].split(3)).to eq([[1, 2], [4, 5]]) end it "to be [[1, 2], [4, 5], [7, 8], [10]]" do expect((1..10).to_a.split { |i| i % 3 == 0 }).to eq([[1, 2], [4, 5], [7, 8], [10]]) end end describe "#strip" do it "to be ['this', 'is', 'a', 'test']" do expect("this is a test".split(" ").strip).to eq(["this", "is", "a", "test"]) end it "to be ['this', 'that']" do expect(["this", "", "that", nil, false].strip).to eq(["this", "that"]) end end describe "#to" do it "to be [1]" do expect([1, 2, 3].to(0)).to eq([1]) end it "to be [1, 2]" do expect([1, 2, 3].to(1)).to eq([1, 2]) end it "to be [1, 2, 3]" do expect([1, 2, 3].to(-1)).to eq([1, 2, 3]) end end describe "#to_sentence" do it "to be ''" do expect([].to_sentence).to eq('') end it "to be 'one'" do expect(["one"].to_sentence).to eq("one") end it "to be 'one and two'" do expect(["one", "two"].to_sentence).to eq("one and two") end it "to be 'one, two, and three'" do expect(["one", "two", "three"].to_sentence).to eq("one, two, and three") end it "to be 'one-two'" do expect(["one", "two"].to_sentence(two_words_connector: '-')).to eq("one-two") end it "to be 'one or two or at least three'" do expect(["one", "two", "three"].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ')).to eq("one or two or at least three") end end end