Sha256: 0d95b312f82aad8637cac1cac5c897b35c3a6f089feb2122529e8e5de143ebca

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  let(:vector) { Hamster.vector(*values) }

  describe "#cons" do
    let(:cons) { vector << added_value }

    shared_examples "checking adding values" do
      let(:added_vector) { Hamster.vector(*added_values) }

      it "preserves the original" do
        orignal = vector
        vector << added_value
        expect(orignal).to eq(vector)
      end

      it "conss the item to the vector" do
        expect(cons).to eq(added_vector)
      end
    end

    context "with a empty array adding a single item" do
      let(:values) { [] }
      let(:added_value) { "A" }
      let(:added_values) { ["A"] }

      include_examples "checking adding values"
    end

    context "with a single-item array adding a different item" do
      let(:values) { ["A"] }
      let(:added_value) { "B" }
      let(:added_values) { %w[A B] }

      include_examples "checking adding values"
    end

    context "with a single-item array adding a duplicate item" do
      let(:values) { ["A"] }
      let(:added_value) { "A" }
      let(:added_values) { %w[A A] }

      include_examples "checking adding values"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc2 spec/lib/hamster/vector/cons_spec.rb
hamster-1.0.1.pre.rc.1 spec/lib/hamster/vector/cons_spec.rb