summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/spec/game_of_life/plane_spec.rb
blob: 88ce0dc1a3f954a93e51b7175d882cae9527dc32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

RSpec.describe GameOfLife::Plane do
  describe "#[]" do
    context "when empty" do
      subject(:cyclic_array) { described_class.new }

      it "returns nil with [-1]" do
        expect(cyclic_array[-1]).to be_nil
      end

      it "returns nil with [0]" do
        expect(cyclic_array[0]).to be_nil
      end

      it "returns nil with [1]" do
        expect(cyclic_array[1]).to be_nil
      end
    end

    context "when not empty" do
      subject(:cyclic_array) { described_class.new([0, 1, 2, 3]) }

      it "returns value at index" do
        expect(cyclic_array[0]).to eq 0
      end

      it "returns value at -index (negative indices count backward from the end of the array)" do
        expect(cyclic_array[-5]).to eq 3
        expect(cyclic_array[-1]).to eq 3
      end

      it "returns value at any index (indices bigger than size cycle again from the beginning)" do
        expect(cyclic_array[5]).to eq 1
        expect(cyclic_array[9]).to eq 1
      end
    end
  end
end