Mercurial > sypikslang
diff gamelib/tests/test_schematics.py @ 54:168cfac9a445
Power and reliability.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 07 May 2012 22:43:54 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/tests/test_schematics.py Mon May 07 22:43:54 2012 +0200 @@ -0,0 +1,55 @@ +from unittest import TestCase + +from gamelib.schematics import Schematic + + +class WaterPistol(Schematic): + NAME = "water pistol" + + # Power and reliability + PROTOTYPE_RELIABILITY = 0.4 + PRODUCTION_RELIABILITY = 0.8 + BASE_POWER = 5 + POWER_INCREMENT = 2 + + +class TestSchematic(TestCase): + def assertNearlyEqual(self, a, b, epsilon=0.001): + if abs(a - b) > epsilon: + self.assertEqual(a, b) + + def test_schematic_reliability(self): + gun = WaterPistol() + self.assertNearlyEqual(0.4, gun.reliability()) + gun.spend_point() + self.assertNearlyEqual(0.8, gun.reliability()) + gun.spend_point() + self.assertNearlyEqual(0.91, gun.reliability()) + gun.spend_point() + self.assertNearlyEqual(0.96, gun.reliability()) + + def test_schematic_power(self): + gun = WaterPistol() + self.assertEqual(5, gun.power()) + gun.spend_point() + self.assertEqual(7, gun.power()) + gun.spend_point() + self.assertEqual(9, gun.power()) + gun.spend_point() + self.assertEqual(11, gun.power()) + + def test_schematic_power_none(self): + gun = WaterPistol() + gun.BASE_POWER = None + self.assertEqual(None, gun.power()) + gun.spend_point() + self.assertEqual(None, gun.power()) + + def test_schematic_power_static(self): + gun = WaterPistol() + gun.POWER_INCREMENT = None + self.assertEqual(5, gun.power()) + gun.spend_point() + self.assertEqual(5, gun.power()) + gun.spend_point() + self.assertEqual(5, gun.power())