summaryrefslogtreecommitdiffstats
path: root/spec/board_spec.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-09-17 16:42:02 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-09-17 16:42:02 +0200
commitbd01c2b44a381c1c68d33f4fe8b4654a50ca8190 (patch)
treed9ef71aa690d7ff5ab04def3c2e881b370d03fc7 /spec/board_spec.rb
parente6522764e28c505c314e413f369ab7a42af07cc5 (diff)
downloadcolonial-twilight-bd01c2b44a381c1c68d33f4fe8b4654a50ca8190.zip
colonial-twilight-bd01c2b44a381c1c68d33f4fe8b4654a50ca8190.tar.gz
Board : clean up and specs
Diffstat (limited to 'spec/board_spec.rb')
-rw-r--r--spec/board_spec.rb66
1 files changed, 40 insertions, 26 deletions
diff --git a/spec/board_spec.rb b/spec/board_spec.rb
index a9e0f1e..4f0e7aa 100644
--- a/spec/board_spec.rb
+++ b/spec/board_spec.rb
@@ -25,26 +25,31 @@ 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
+ it 'count spaces' do expect(board.spaces.size).to eq(30) end
+ it 'count sectors' do expect(board.spaces.select(&:sector?).size).to eq(25) end
+ it 'count cities' do expect(board.spaces.select(&:city?).size).to eq(3) end
+ it 'count countries' do expect(board.spaces.select(&:country?).size).to eq(2) end
+ it 'count coastal sectors' do expect(board.spaces.select(&:coastal?).size).to eq(14) end
+ it 'count border sectors' do expect(board.spaces.select(&:border?).size).to eq(9) end
+ it 'count mountain sectors' do expect(board.spaces.select(&:mountain?).size).to eq(21) end
+ it 'count no mountain sectors' do expect(board.spaces.reject(&:mountain?).size).to eq(9) end
+ it 'count city sectors' do expect(board.spaces.select(&:city?).size).to eq(3) end
+ it 'count 0 pop sectors' do expect(board.spaces.select { |s| s.pop == 0 }.size).to eq(11) end
+ it 'count 1 pop sectors' do expect(board.spaces.select { |s| s.pop == 1 }.size).to eq(9) end
+ it 'count 2 pop sectors' do expect(board.spaces.select { |s| s.pop == 2 }.size).to eq(9) end
+ it 'count 3 pop sectors' do expect(board.spaces.select { |s| s.pop == 3 }.size).to eq(1) end
+ it 'count resettled sectors' do expect(board.spaces.select { |s| s.resettled }.size).to eq(0) 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 'count 0 pop sectors' do expect(board.spaces.select { |s| s.pop == 0 }.size).to eq(14) end
+ it 'count 1 pop sectors' do expect(board.spaces.select { |s| s.pop == 1 }.size).to eq(6) end
+ it 'count resettled sectors' do expect(board.spaces.select(&:resettled).size).to eq(3) end
it 'countries are independent' do expect(board.spaces.select(&:country?).select(&:independent?).size).to eq(2) end
+ it 'compute opposition bases' do expect(board.compute_opposition_bases).to eq(19) end
+ it 'compute support commitment' do expect(board.compute_support_commitment).to eq(22) 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
@@ -61,20 +66,29 @@ describe ColonialTwilight::Board do
it 'support + commitment' do expect(board.support_commitment).to eq(22) end
end
- describe 'has / count' do
+ describe 'search / has / count' do
board = ColonialTwilight::Board.new
board.load :short
+ it 'search sectors' do expect(board.search(:sector).size).to eq(25) end
+ it 'search cities' do expect(board.search(:city).size).to eq(3) end
+ it 'search countries' do expect(board.search(:country).size).to eq(2) end
+ it 'search sectors' do expect(board.search(:sectors).size).to eq(25) end
+ it 'search cities' do expect(board.search(:cities).size).to eq(3) end
+ it 'search countries' do expect(board.search(:countries).size).to eq(2) end
+ it 'search sectors' do expect(board.search(&:sector?).size).to eq(25) end
+ it 'search cities' do expect(board.search(&:city?).size).to eq(3) end
+ it 'search countries' do expect(board.search(&:country?).size).to eq(2) end
+ it 'search fln 0 pop' do expect(board.search { |s| s.pop.zero? && s.fln.positive? }.size).to eq(2) end
+ it 'search fln 1 pop' do expect(board.search { |s| s.pop == 1 && s.fln.positive? }.size).to eq(4) end
+ it 'search fln 2 pop' do expect(board.search { |s| s.pop == 2 && s.fln.positive? }.size).to eq(4) end
+ it 'search fln 3 pop' do expect(board.search { |s| s.pop == 3 && s.fln.positive? }.size).to eq(0) end
+ it 'has fln 0 pop' do expect(board.has { |s| s.pop.zero? && s.fln.positive? }).to be true end
+ it 'has fln 1 pop' do expect(board.has { |s| s.pop == 1 && s.fln.positive? }).to be true end
+ it 'has fln 2 pop' do expect(board.has { |s| s.pop == 2 && s.fln.positive? }).to be true end
+ it 'has fln 3 pop' do expect(board.has { |s| s.pop == 3 && s.fln.positive? }).to be false end
it 'count fln_bases' do expect(board.count(&:fln_bases)).to eq(8) end
- it 'count fln with bases' do expect(board.count { |s| s.fln_bases_0? ? 0 : s.guerrillas }).to eq(13) end
- it 'count fln without bases' do expect(board.count { |s| s.fln_bases_0? ? s.guerrillas : 0 }).to eq(4) end
- it 'count fln in country' do expect(board.count { |s| s.country? ? s.guerrillas : 0 }).to eq(9) end
- it 'has fln 0 pop' do expect(board.search { |s| s.pop0? && s.fln.positive? }.size).to eq(2) end
- it 'has fln 0 pop' do expect(board.search { |s| s.pop == 1 && s.fln.positive? }.size).to eq(4) end
- it 'has fln 0 pop' do expect(board.search { |s| s.pop == 2 && s.fln.positive? }.size).to eq(4) end
- it 'has fln 0 pop' do expect(board.search { |s| s.pop == 3 && s.fln.positive? }.size).to eq(0) end
- it 'has fln 0 pop' do expect(board.has { |s| s.pop0? && s.fln.positive? }).to be true end
- it 'has fln 0 pop' do expect(board.has { |s| s.pop == 1 && s.fln.positive? }).to be true end
- it 'has fln 0 pop' do expect(board.has { |s| s.pop == 2 && s.fln.positive? }).to be true end
- it 'has fln 0 pop' do expect(board.has { |s| s.pop == 3 && s.fln.positive? }).to be false end
+ it 'count fln with bases' do expect(board.count { |s| s.fln_bases.zero? ? 0 : s.fln_cubes }).to eq(13) end
+ it 'count fln without bases' do expect(board.count { |s| s.fln_bases.zero? ? s.fln_cubes : 0 }).to eq(4) end
+ it 'count fln in country' do expect(board.count { |s| s.country? ? s.fln_cubes : 0 }).to eq(9) end
end
end