summaryrefslogtreecommitdiffstats
path: root/spec/forces_spec.rb
blob: 549b91719e072190256342c5364cd4205b8143c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# frozen_string_literal: true

require './lib/colonial_twilight/forces'

describe ColonialTwilight::Forces do
  describe 'Available' do
    f = ColonialTwilight::Forces.new :available
    it 'nil' do
      %i[control fln_active].each do |sym|
        expect(f.send(sym)).to be nil
      end
    end

    it 'fln_active -> fln_underground' do
      f.add :fln_active, 1
      expect(f.fln_underground).to be 1
    end
  end

  describe 'Casualties' do
    f = ColonialTwilight::Forces.new :casualties
    it 'nil' do
      %i[control fln_active fln_bases].each do |sym|
        expect(f.send(sym)).to be nil
      end
    end

    it 'raise' do
      %i[fln_active fln_bases].each do |sym|
        expect { f.add sym, 1 }.to raise_error(Exception)
      end
    end
  end

  describe 'OutOfPlay' do
    f = ColonialTwilight::Forces.new :out_of_play
    it 'nil' do
      %i[control algerian_troops algerian_police fln_active fln_bases].each do |sym|
        expect(f.send(sym)).to be nil
      end
    end

    it 'raise' do
      %i[algerian_troops algerian_police fln_active fln_bases].each do |sym|
        expect { f.add sym, 1 }.to raise_error(Exception)
      end
    end
  end

  describe 'Country' do
    f = ColonialTwilight::Forces.new :Country
    it 'nil' do
      %i[control algerian_troops algerian_police french_troops french_police].each do |sym|
        expect(f.send(sym)).to be nil
      end
    end

    it 'raise' do
      %i[algerian_troops algerian_police french_troops french_police].each do |sym|
        expect { f.add sym, 1 }.to raise_error(Exception)
      end
    end
  end

  describe 'City' do
    ColonialTwilight::Forces.new :City
  end

  describe 'Sector' do
    f = ColonialTwilight::Forces.new :Sector
    data = { fln_bases: 0, gov_bases: 1, algerian_troops: 2, algerian_police: 3,
             french_troops: 4, french_police: 5, fln_underground: 6, fln_active: 7 }
    f.init data
    it 'init' do
      data.keys.each_with_index do |k, i|
        expect(f.send(k)).to be i
      end
    end

    it 'count bases' do
      expect(f.bases).to be 1
    end

    it 'count fln' do
      expect(f.fln).to be 13
    end

    it 'count guerrillas' do
      expect(f.guerrillas).to be 13
    end

    it 'count troops' do
      expect(f.troops).to be 6
    end

    it 'count police' do
      expect(f.police).to be 8
    end

    it 'switch control' do
      expect(f.control).to be :GOV
      f.add :fln_active, 2
      expect(f.control).to be :uncontrolled
      f.add :fln_active, 1
      expect(f.control).to be :FLN
    end

    it 'inspect' do
      expect(f.inspect.instance_of?(String)).to be true
    end

    it 'raise' do
      expect { f.add :fln_bases, 2 }.to raise_error(Exception)
    end

    it 'raise wrong type' do
      expect { f.add :wrong, 1 }.to raise_error(Exception)
    end

    it 'data' do
      d = f.data
      data.keys do |k, v|
      expect(d[k]).to be v
      end
    end
  end
end