view gamelib/tests/test_schematics.py @ 247:594c45f0f685

Don't reward science or schematics when we know everything
author Neil Muller <drnlmuller@gmail.com>
date Sun, 13 May 2012 00:50: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())