Mercurial > sypikslang
view gamelib/tests/test_schematics.py @ 130:8f717b2b3378
Advance milestone
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 10 May 2012 16:46:18 +0200 |
parents | 168cfac9a445 |
children |
line wrap: on
line source
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())