54
|
1 from unittest import TestCase
|
|
2
|
|
3 from gamelib.schematics import Schematic
|
|
4
|
|
5
|
|
6 class WaterPistol(Schematic):
|
|
7 NAME = "water pistol"
|
|
8
|
|
9 # Power and reliability
|
|
10 PROTOTYPE_RELIABILITY = 0.4
|
|
11 PRODUCTION_RELIABILITY = 0.8
|
|
12 BASE_POWER = 5
|
|
13 POWER_INCREMENT = 2
|
|
14
|
|
15
|
|
16 class TestSchematic(TestCase):
|
|
17 def assertNearlyEqual(self, a, b, epsilon=0.001):
|
|
18 if abs(a - b) > epsilon:
|
|
19 self.assertEqual(a, b)
|
|
20
|
|
21 def test_schematic_reliability(self):
|
|
22 gun = WaterPistol()
|
|
23 self.assertNearlyEqual(0.4, gun.reliability())
|
|
24 gun.spend_point()
|
|
25 self.assertNearlyEqual(0.8, gun.reliability())
|
|
26 gun.spend_point()
|
|
27 self.assertNearlyEqual(0.91, gun.reliability())
|
|
28 gun.spend_point()
|
|
29 self.assertNearlyEqual(0.96, gun.reliability())
|
|
30
|
|
31 def test_schematic_power(self):
|
|
32 gun = WaterPistol()
|
|
33 self.assertEqual(5, gun.power())
|
|
34 gun.spend_point()
|
|
35 self.assertEqual(7, gun.power())
|
|
36 gun.spend_point()
|
|
37 self.assertEqual(9, gun.power())
|
|
38 gun.spend_point()
|
|
39 self.assertEqual(11, gun.power())
|
|
40
|
|
41 def test_schematic_power_none(self):
|
|
42 gun = WaterPistol()
|
|
43 gun.BASE_POWER = None
|
|
44 self.assertEqual(None, gun.power())
|
|
45 gun.spend_point()
|
|
46 self.assertEqual(None, gun.power())
|
|
47
|
|
48 def test_schematic_power_static(self):
|
|
49 gun = WaterPistol()
|
|
50 gun.POWER_INCREMENT = None
|
|
51 self.assertEqual(5, gun.power())
|
|
52 gun.spend_point()
|
|
53 self.assertEqual(5, gun.power())
|
|
54 gun.spend_point()
|
|
55 self.assertEqual(5, gun.power())
|