summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-10-23 19:08:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-10-23 19:08:21 +0200
commit8b34966151c15a4fb022a6205c8143b90f38f625 (patch)
treeb222351dad7761c7364298044f246b062244730d
parent6822431aa1d93a11a8ab266284783814747721f3 (diff)
downloadcolonial-twilight-8b34966151c15a4fb022a6205c8143b90f38f625.zip
colonial-twilight-8b34966151c15a4fb022a6205c8143b90f38f625.tar.gz
FLNRules : use mock Board and Sector
-rw-r--r--spec/fln_rules_spec.rb37
-rw-r--r--spec/mock_board.rb82
2 files changed, 105 insertions, 14 deletions
diff --git a/spec/fln_rules_spec.rb b/spec/fln_rules_spec.rb
index fe8e301..1b55288 100644
--- a/spec/fln_rules_spec.rb
+++ b/spec/fln_rules_spec.rb
@@ -2,6 +2,7 @@
require './lib/colonial_twilight/fln_rules'
require './lib/colonial_twilight/board'
+require './spec/mock_board'
class FLNRulesImpl
include ColonialTwilight::FLNRules
@@ -25,31 +26,39 @@ describe ColonialTwilight::FLNRules do
expect(rules.rally_spaces(@board).size).to eq(27)
end
- it 'may_rally_in? not in city at support' do
- a = ColonialTwilight::City.new('a', 'w', 0, 0)
- a.shift :support
- expect(rules.may_rally_in?(a)).to be false
+ it 'may_rally_in? sector' do
+ a = Sector.new
+ expect(rules.may_rally_in?(a)).to be true
end
- it 'may_rally_in? not in not independent country' do
- a = ColonialTwilight::Country.new('country')
+ it 'may_rally_in? in city not at support' do
+ a = Sector.new({ name: 'city', support: false })
+ expect(rules.may_rally_in?(a)).to be true
+ end
+
+ it 'may_rally_in? not in city at support' do
+ a = Sector.new({ name: 'city', support: true })
expect(rules.may_rally_in?(a)).to be false
end
- it 'may_rally_in?' do
- a = ColonialTwilight::Sector.new('a', 'w', 0, 0)
+ it 'may_rally_in? in independent country' do
+ a = Sector.new({ name: 'country', independent: true })
expect(rules.may_rally_in?(a)).to be true
end
- it 'may place 1 FLN cube' do
- a = ColonialTwilight::Sector.new('a', 'w', 0, 0)
+ it 'may_rally_in? not in not independent country' do
+ a = Sector.new({ name: 'country', independent: false })
+ expect(rules.may_rally_in?(a)).to be false
+ end
+
+ it 'may place 1 guerrillas' do
+ a = Sector.new({ pop: 3 })
expect(rules.max_placable_guerrillas(a)).to eq(1)
end
- it 'may place 2 FLN cube' do
- a = ColonialTwilight::Sector.new('a', 'w', 0, 2)
- a.add :fln_base
- expect(rules.max_placable_guerrillas(a)).to eq(3)
+ it 'may place pop + base guerrillas' do
+ a = Sector.new({ pop: 3, fln_bases: 2 })
+ expect(rules.max_placable_guerrillas(a)).to eq(5)
end
end
diff --git a/spec/mock_board.rb b/spec/mock_board.rb
new file mode 100644
index 0000000..18dad5b
--- /dev/null
+++ b/spec/mock_board.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+class Sector
+ attr_reader :name
+ attr_writer :data
+
+ def initialize(data = { name: 'sector', pop: 0, fln_bases: 0, fln_active: 0, fln_underground: 0, gov_cubes: 0, independent: true, support: false, terror: false })
+ @name = data[:name] || 'sector'
+ @data = data
+ end
+
+ def sector?
+ @name == 'sector'
+ end
+
+ def city?
+ @name == 'city'
+ end
+
+ def country?
+ @name == 'country'
+ end
+
+ def max_bases
+ 3
+ end
+
+ def independent?
+ @data[:independent]
+ end
+
+ def support?
+ @data[:support]
+ end
+
+ def terror?
+ @data[:terror]
+ end
+
+ def pop
+ @data[:pop] || 0
+ end
+
+ def guerrillas
+ fln_active + fln_underground
+ end
+
+ def fln_bases
+ @data[:fln_bases] || 0
+ end
+
+ def fln_active
+ @data[:fln_active] || 0
+ end
+
+ def fln_underground
+ @data[:fln_underground] || 0
+ end
+
+ def gov_cubes
+ @data[:gov_cubes] || 0
+ end
+end
+
+class Board
+ attr_reader :sector
+ attr_accessor :fln_resources, :available_fln_bases
+
+ def initialize
+ @fln_resources = 0
+ @available_fln_bases = 1
+ @sector = Sector.new
+ end
+
+ def has(&block)
+ block.call(@sector)
+ end
+
+ def count(&block)
+ block.call(@sector)
+ end
+end