summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/spec
diff options
context:
space:
mode:
authora14m <[email protected]>2020-12-03 13:33:02 +0100
committera14m <[email protected]>2020-12-03 15:03:09 +0100
commit27b78771d819c4d9c1fe8537429d16fbc41d6a34 (patch)
treecd67f8de5e29e65463b5684c7e9e3477c9cdbcae /CLI/ruby/spec
parent05730269d4d2d690d871548ae3930d3ce20cdcad (diff)
Add the GameOfLife module API for generating universes and running them
Diffstat (limited to 'CLI/ruby/spec')
-rw-r--r--CLI/ruby/spec/game_of_life_spec.rb72
1 files changed, 70 insertions, 2 deletions
diff --git a/CLI/ruby/spec/game_of_life_spec.rb b/CLI/ruby/spec/game_of_life_spec.rb
index 5c93709..b4c1710 100644
--- a/CLI/ruby/spec/game_of_life_spec.rb
+++ b/CLI/ruby/spec/game_of_life_spec.rb
@@ -1,7 +1,75 @@
# frozen_string_literal: true
RSpec.describe GameOfLife do
- it "has a version number" do
- expect(GameOfLife::VERSION).not_to be nil
+ describe ".generate" do
+ let(:options) do
+ {
+ "live-cell" => "L",
+ "dead-cell" => "D",
+ "delay" => 100,
+ "width" => 10,
+ "height" => 20,
+ "seed" => 500,
+ }
+ end
+
+ context "with options['input']" do
+ before { options["input"] = "./file.txt" }
+
+ it "defines configurations constants" do
+ expect(described_class::Cell).to receive(:const_set).with(:LIVE_CELL, "L")
+ expect(described_class::Cell).to receive(:const_set).with(:DEAD_CELL, "D")
+ expect(described_class).to receive(:const_set).with(:DELAY, 100.0)
+ expect(described_class).to receive(:const_set).with(:BANNER, "Input: ./file.txt")
+
+ allow(described_class::Generators::Input).to receive(:new)
+ described_class.generate(options)
+ end
+
+ it "calls Generators::Input.new" do
+ allow(described_class::Cell).to receive(:const_set)
+ allow(described_class).to receive(:const_set)
+
+ expect(described_class::Generators::Input).to receive(:new).with(options)
+ described_class.generate(options)
+ end
+ end
+
+ context "without options['input']" do
+ before { options["seed"] = 1337 }
+
+ it "defines configurations constants" do
+ expect(described_class::Cell).to receive(:const_set).with(:LIVE_CELL, "L")
+ expect(described_class::Cell).to receive(:const_set).with(:DEAD_CELL, "D")
+ expect(described_class).to receive(:const_set).with(:DELAY, 100.0)
+ expect(described_class).to receive(:const_set).with(:BANNER, "Seed: 1337")
+
+ allow(described_class::Generators::Seed).to receive(:new)
+ described_class.generate(options)
+ end
+
+ it "calls Generators::Seed.new (and raises error)" do
+ allow(described_class::Cell).to receive(:const_set)
+ allow(described_class).to receive(:const_set)
+
+ expect { described_class.generate(options) }.to raise_error(NotImplementedError)
+ end
+ end
+ end
+
+ describe ".run" do
+ let(:universe) { GameOfLife::Universe.new(width: 3, height: 3) }
+
+ it "calls universe#evolve! and #{described_class}.run" do
+ # allow kernel loop tiwce
+ allow(Kernel).to receive(:loop).and_yield.and_yield
+
+ expect(described_class).to receive(:render).with(universe).twice
+ expect(universe).to receive(:evolve!).twice
+
+ described_class.run(universe)
+ end
end
+
+ describe.pending ".render"
end