-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·92 lines (79 loc) · 3.14 KB
/
tests.py
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
#!/usr/bin/python
import unittest
import monsters
import simfile
import optimizer
class MonsterTest(unittest.TestCase):
def test_hard_win(self):
attacker = monsters.Skeleton(550)
defender = monsters.ArchDevil(5)
result = attacker.fight_with(defender)
self.assertEqual(result, (1, 0))
def test_hard_win2(self):
attacker = monsters.Skeleton(555)
defender = monsters.ArchDevil(5)
result = attacker.fight_with(defender)
self.assertEqual(result, (6, 0))
def test_hard_loss(self):
attacker = monsters.BoneDragon(2)
defender = monsters.Cerberus(27)
result = attacker.fight_with(defender)
self.assertEqual(result, (0, 1))
def test_hard_loss(self):
attacker = monsters.BoneDragon(1)
defender = monsters.Cerberus(27)
result = attacker.fight_with(defender)
self.assertEqual(result, (0, 14))
def test_bonus_win(self):
attacker = monsters.Skeleton(24)
defender = monsters.Cerberus(7)
result = attacker.fight_with(defender)
self.assertEqual(result, (1, 0))
def test_vampire_marksman(self):
attacker = monsters.Vampire(7)
defender = monsters.Marksman(21)
result = attacker.fight_with(defender)
self.assertEqual(result, (0, 12))
class SimfileTest(unittest.TestCase):
def test_open_simfile(self):
army1, army2 = simfile.get_army('test1.sim')
self.assertEqual(len(army1), 6)
self.assertEqual(len(army2), 3)
def test_fight_lose_simfile(self):
army1, army2 = simfile.get_army('test1.sim')
result, report = army1.attack(army2)
self.assertFalse(result)
self.assertEqual(len(army1), 0)
# no one harmed, that angel killed them all ;-)
self.assertEqual(len(army2), 3)
self.assertEqual(len(filter(lambda x: x == (0, 1), report.leftovers())), 6)
def test_fight_win_simfile(self):
army1, army2 = simfile.get_army('test1.sim')
army1[0].stack += 10 # vampires
result, report = army1.attack(army2, dry_run=False)
self.assertTrue(result)
self.assertEqual(len(army1), 2)
self.assertEqual(len(army2), 0)
self.assertEqual(army1[0].stack, 4)
self.assertEqual(
report.leftovers(),
[(7, 0), (0, 12), (0, 2), (5, 0), (0, 5), (0, 4), (4, 0)]
)
def test_hard_battle(self):
army1, army2 = simfile.get_army('test1.sim')
result, report = army1.attack(army2)
self.assertFalse(result)
def test_dry_run(self):
army1, army2 = simfile.get_army('test1.sim')
result1, report1 = army1.attack(army2, dry_run=True)
result2, report2 = army1.attack(army2, dry_run=True)
self.assertEqual(result1, result2)
self.assertEqual(report1.leftovers(), report2.leftovers())
class OptimizerTest(unittest.TestCase):
def test_optimize(self):
army1, army2 = simfile.get_army('test3.sim')
best = optimizer.optimize(army1, army2, show_pbar=False)
self.assertEqual(best[0].stack, 119)
self.assertEqual(best[1].stack, 5)
if __name__ == '__main__':
unittest.main()