# 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