Sha256: 5a1aeacfc56be599b54266f3130b4ef6ce7c5b7188a97adbd52fdec95e01f735

Contents?: true

Size: 988 Bytes

Versions: 3

Compression:

Stored size: 988 Bytes

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  let(:vector) { V[*values] }

  describe "#last" do
    let(:last) { vector.last }

    shared_examples "checking values" do
      it "returns the last item" do
        expect(last).to eq(last_item)
      end
    end

    context "with an empty vector" do
      let(:last_item) { nil }
      let(:values) { [] }

      include_examples "checking values"
    end

    context "with a single item vector" do
      let(:last_item) { "A" }
      let(:values) { %w[A] }

      include_examples "checking values"
    end

    context "with a multi-item vector" do
      let(:last_item) { "B" }
      let(:values) { %w[A B] }

      include_examples "checking values"
    end

    [31, 32, 33, 1023, 1024, 1025].each do |size|
      context "with a #{size}-item vector" do
        let(:last_item) { size }
        let(:values) { (1..size).to_a }

        include_examples "checking values"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/vector/last_spec.rb
hamster-3.0.0 spec/lib/hamster/vector/last_spec.rb
hamster-2.0.0 spec/lib/hamster/vector/last_spec.rb