summaryrefslogtreecommitdiffstats
path: root/spec/spaces_spec.rb
blob: 0c7e6bc8490bb42e52de258a94584aa4f071f4c2 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# frozen_string_literal: true

require './lib/colonial_twilight/spaces'
# require './spec/mock_board'

describe ColonialTwilight::Track do
  before do
    @t = ColonialTwilight::Track.new(10)
  end

  it 'initialize' do
    expect(@t.v).to eq 0
  end

  it 'shift' do
    expect(@t.shift(3)).to eq 3
    expect(@t.shift(-2)).to eq 1
  end

  it 'clamp' do
    expect(@t.clamp(12)).to eq 10
  end

  it 'overflow' do
    expect { @t.shift(11) }.to raise_error(Exception)
  end

  it 'data' do
    expect(@t.shift(3)).to eq 3
    expect(@t.data).to eq 3
  end
end

describe ColonialTwilight::Sector do
  before do
    @s = ColonialTwilight::Sector.new('Name', 'Wilaya', 'I', 0)
  end

  it 'to_s data inspect' do
    expect(@s.to_s).to eq 'Name'
    expect(@s.data.instance_of?(Hash)).to be true
    expect(@s.inspect.instance_of?(String)).to be true
  end

  it 'is a Sector' do
    expect(@s.sector?).to be true
    expect(@s.city?).to be false
    expect(@s.country?).to be false
  end

  it 'has border' do
    s = ColonialTwilight::Sector.new('Name', 'Wilaya', 'I', 1, ColonialTwilight::Sector::BORDER)
    expect(s.border?).to be true
    expect(s.coastal?).to be false
    expect(s.mountain?).to be false
  end

  it 'is coastal' do
    s = ColonialTwilight::Sector.new('Name', 'Wilaya', 'I', 1, ColonialTwilight::Sector::COASTAL)
    expect(s.border?).to be false
    expect(s.coastal?).to be true
    expect(s.mountain?).to be false
  end

  it 'has mountains' do
    s = ColonialTwilight::Sector.new('Name', 'Wilaya', 'I', 1, ColonialTwilight::Sector::MOUNTAIN)
    expect(s.border?).to be false
    expect(s.coastal?).to be false
    expect(s.mountain?).to be true
  end

  it 'has all' do
    s = ColonialTwilight::Sector.new('Name', 'Wilaya', 'I', 1, ColonialTwilight::Sector::BORDER ||
      ColonialTwilight::Sector::COASTAL || ColonialTwilight::Sector::MOUNTAIN)
    expect(s.border?).to be true
    expect(s.coastal?).to be false
    expect(s.mountain?).to be false
  end

  it 'terror' do
    expect(@s.terror?).to be false
    expect(@s.terror).to eq 0
    @s.shift_terror 2
    expect(@s.terror?).to be true
    expect(@s.terror).to eq 2
    expect { @t.shift_terrort(-3) }.to raise_error(Exception)
  end

  it 'alignment' do
    expect(@s.oppose?).to be false
    expect(@s.neutral?).to be true
    expect(@s.support?).to be false
    expect { @s.shift :wrong }.to raise_error(Exception)
  end

  it 'shift alignment toward oppose' do
    @s.shift :oppose
    expect(@s.oppose?).to be true
    expect(@s.neutral?).to be false
    expect(@s.support?).to be false
  end

  it 'shift alignment toward support' do
    @s.shift :support
    expect(@s.oppose?).to be false
    expect(@s.neutral?).to be false
    expect(@s.support?).to be true
  end

  it 'control' do
    expect(@s.fln_control?).to be false
    expect(@s.uncontrolled?).to be true
    expect(@s.gov_control?).to be false
  end

  it 'control fln' do
    @s.add :fln_active
    expect(@s.fln_control?).to be true
    expect(@s.uncontrolled?).to be false
    expect(@s.gov_control?).to be false
  end

  it 'control gov' do
    @s.add :french_troops
    expect(@s.fln_control?).to be false
    expect(@s.uncontrolled?).to be false
    expect(@s.gov_control?).to be true
  end

  it 'resettle' do
    expect { @s.resettle! }.to raise_error(Exception)
    @s.pop = 2
    expect { @s.resettle! }.to raise_error(Exception)
    @s.pop = 1
    @s.resettle!
    expect(@s.resettled?).to be true
    expect(@s.pop).to eq 0
  end
end

describe ColonialTwilight::City do
  before do
    @c = ColonialTwilight::City.new('Name', 'Wilaya', 'I', 0)
  end

  it 'is a City' do
    expect(@c.sector?).to be false
    expect(@c.city?).to be true
    expect(@c.country?).to be false
  end
end

describe ColonialTwilight::Country do
  before do
    @c = ColonialTwilight::Country.new('Name')
  end

  it 'is a Coutry' do
    expect(@c.sector?).to be false
    expect(@c.city?).to be false
    expect(@c.country?).to be true
  end

  it 'independent' do
    expect(@c.independent?).to be false
    @c.independent!
    expect(@c.independent?).to be true
  end
end