summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/spec/game_of_life/generators/seed_spec.rb
blob: b9f9ed2401db6cad0f3415faf7b29dee64671677 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true

RSpec.describe GameOfLife::Generators::Seed do
  describe ".new" do
    it "returns a GameOfLife::Universe" do
      options = { "seed" => 1, "width" => 1, "height" => 1 }
      expect(described_class.new(options)).to be_a GameOfLife::Universe
    end

    context "when seed => 1" do
      it "returns the same universe for width => 10, height => 1" do
        options = { "seed" => 1, "width" => 10, "height" => 1 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "..X..X.XXX"
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 1" do
        options = { "seed" => 1, "width" => 20, "height" => 1 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "..X..X.XXXXX.X..XX.."
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 2" do
        options = { "seed" => 1, "width" => 20, "height" => 2 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "..X..X.XXXXX.X..XX..\n" \
                   "...X.XX.X.X.XXX.X.XX"
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 3" do
        options = { "seed" => 1, "width" => 20, "height" => 3 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "..X..X.XXXXX.X..XX..\n" \
                   "...X.XX.X.X.XXX.X.XX\n" \
                   "X........X...XXXXXXX"
        expect(described_class.new(options).to_s).to eq universe
      end
    end

    context "when seed => 2" do
      it "returns the same universe for width => 10, height => 1" do
        options = { "seed" => 2, "width" => 10, "height" => 1 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "X.X.X....X"
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 1" do
        options = { "seed" => 2, "width" => 20, "height" => 1 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "X.X.X....X.XXX..X..X"
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 2" do
        options = { "seed" => 2, "width" => 20, "height" => 2 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "X.X.X....X.XXX..X..X\n" \
                   "XX.X.XX.XXXX....XXXX"
        expect(described_class.new(options).to_s).to eq universe
      end

      it "returns the same universe for width => 20, height => 3" do
        options = { "seed" => 2, "width" => 20, "height" => 3 }
        stub_const("GameOfLife::Cell::LIVE_CELL", "X")
        stub_const("GameOfLife::Cell::DEAD_CELL", ".")

        universe = "X.X.X....X.XXX..X..X\n" \
                   "XX.X.XX.XXXX....XXXX\n" \
                   "X...X.X..XX....X..X."
        expect(described_class.new(options).to_s).to eq universe
      end
    end
  end
end