-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattacks_spec.rb
98 lines (72 loc) · 1.88 KB
/
attacks_spec.rb
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
require './attacks.rb'
require './settings.rb'
RSpec.describe "attacks" do
# market prices
markets = []
$settings[:resourceTypes].each do |resourceType|
markets << {
:type => resourceType,
:value => 10.0
}
end
it "gets number of soldiers" do
army = {
:footmen => 3,
:archers => 5
}
getNumberOfSoldiers(army)
expect(army[:numSoldiers]).to eq(8)
end
it "gets percentage" do
army = {
:footmen => 3,
:archers => 5
}
getPercentage(army)
expect(army[:percentage][:footman]).to eq(3.0/8.0)
expect(army[:percentage][:archer]).to eq(5.0/8.0)
expect(army[:percentage][:knight]).to eq(0.0)
end
it "gets correct winnings for 1 soldier" do
attackingArmy = {
:footmen => 1,
:numSoldiers => 1,
:numLoses => 0,
:isWinner => true
}
defendingArmy = {
:footmen => 0,
:gold => 10000.0
}
winnings = getWinnings(attackingArmy, defendingArmy, markets)
expect(winnings[:gold]).to eq($settings[:winningsSoldierCanCarry])
end
it "gets correct winnings for 10 soldier" do
attackingArmy = {
:footmen => 10,
:numSoldiers => 10,
:numLoses => 0,
:isWinner => true
}
defendingArmy = {
:footmen => 0,
:gold => 10000.0
}
winnings = getWinnings(attackingArmy, defendingArmy, markets)
expect(winnings[:gold]).to eq($settings[:winningsSoldierCanCarry] * attackingArmy[:footmen])
end
it "gets correct winnings for max $settings[:battleWinnings]" do
attackingArmy = {
:footmen => 10,
:numSoldiers => 10,
:numLoses => 0,
:isWinner => true
}
defendingArmy = {
:footmen => 0,
:gold => 100.0
}
winnings = getWinnings(attackingArmy, defendingArmy, markets)
expect(winnings[:gold]).to eq(defendingArmy[:gold] * $settings[:battleWinnings])
end
end