summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-09-11 13:44:48 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-09-11 13:44:48 +0200
commit50686dd6037e7487479599c80890a683800f6a19 (patch)
tree3068eaa45cf08d3058aa8f371d8af5d8dc1f63b5 /spec
parent3616bd0a7dfe2235624b1ae97937b27899eaf75f (diff)
downloadcolonial-twilight-50686dd6037e7487479599c80890a683800f6a19.zip
colonial-twilight-50686dd6037e7487479599c80890a683800f6a19.tar.gz
Board : implement specs
Diffstat (limited to 'spec')
-rw-r--r--spec/board_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/board_spec.rb b/spec/board_spec.rb
new file mode 100644
index 0000000..d1defd4
--- /dev/null
+++ b/spec/board_spec.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require './lib/colonial_twilight/board'
+
+def compute(board)
+ vals = [0] * 11
+ board.spaces.each do |s|
+ vals[0] += 1 if s.alignment == :support
+ vals[1] += 1 if s.alignment == :oppose
+ vals[2] += 1 if s.control == :GOV
+ vals[3] += 1 if s.control == :FLN
+ unless s.country?
+ vals[4] += s.french_troops
+ vals[5] += s.french_police
+ vals[6] += s.algerian_troops
+ vals[7] += s.algerian_police
+ vals[8] += s.gov_bases
+ end
+ vals[9] += s.fln_underground
+ vals[10] += s.fln_bases
+ end
+ vals
+end
+
+describe ColonialTwilight::Board do
+
+ describe 'board setup' do
+ board = ColonialTwilight::Board.new
+ it 'has spaces' do expect(board.spaces.size).to eq(30) end
+ it 'has sectors' do expect(board.sectors.size).to eq(28) end
+ it 'has country sectors' do expect(board.spaces.select(&:country?).size).to eq(2) end
+ it 'has coastal sectors' do expect(board.spaces.select(&:coastal?).size).to eq(14) end
+ it 'has border sectors' do expect(board.spaces.select(&:border?).size).to eq(9) end
+ it 'has mountain sectors' do expect(board.spaces.select(&:mountain?).size).to eq(21) end
+ it 'has no mountain sectors' do expect(board.spaces.reject(&:mountain?).size).to eq(9) end
+ it 'has city sectors' do expect(board.spaces.select(&:city?).size).to eq(3) end
+ it 'has 0 pop sectors' do expect(board.spaces.select { |s| s.pop == 0 }.size).to eq(11) end
+ it 'has 1 pop sectors' do expect(board.spaces.select { |s| s.pop == 1 }.size).to eq(9) end
+ it 'has 2 pop sectors' do expect(board.spaces.select { |s| s.pop == 2 }.size).to eq(9) end
+ it 'has 3 pop sectors' do expect(board.spaces.select { |s| s.pop == 3 }.size).to eq(1) end
+ end
+
+ describe 'short scenario setup' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ it 'has 0 pop sectors' do expect(board.spaces.select { |s| s.pop == 0 }.size).to eq(14) end
+ it 'has 1 pop sectors' do expect(board.spaces.select { |s| s.pop == 1 }.size).to eq(6) end
+ it 'countries are independent' do expect(board.spaces.select(&:country?).select(&:independent?).size).to eq(2) end
+ vals = compute board
+ it 'total support' do expect(vals[0]).to eq(3) end
+ it 'total opposition' do expect(vals[1]).to eq(7) end
+ it 'total GOV control' do expect(vals[2]).to eq(16) end
+ it 'total FLN control' do expect(vals[3]).to eq(3) end
+ it 'total french troops' do expect(vals[4]).to eq(9) end
+ it 'total french police' do expect(vals[5]).to eq(17) end
+ it 'total algerian troops' do expect(vals[6]).to eq(3) end
+ it 'total algerian police' do expect(vals[7]).to eq(7) end
+ it 'total GOV bases' do expect(vals[8]).to eq(4) end
+ it 'total FLN undergound' do expect(vals[9]).to eq(17) end
+ it 'total FLN bases' do expect(vals[10]).to eq(8) end
+ it 'oppositon + bases' do expect(board.opposition_bases).to eq(19) end
+ it 'support + commitment' do expect(board.support_commitment).to eq (22) end
+ end
+end