@@ -0,0 +1,1578 @@
+# -*- coding: utf-8 -*-%0Afrom gauge import Gauge%0A%0A%0Aclass Energy(Gauge):%0A%0A    min = 0%0A    max = 10%0A    transform = Stairs(+1, 10)  # +1 energy per 10 seconds%0A%0A    def use(self, amount=1, at=None):%0A        return self.decr(amount, at)%0A%0A%0Aclass Life(Gauge):%0A%0A    min = 0%0A    max = 100%0A    transform = Linear(-1, 10)  # -1 life per 10 seconds%0A%0A    def recover(self, amount=1, at=None):%0A        return self.incr(amount, at)%0A%0A    def hurt(self, amount=1, at=None):%0A        return self.decr(amount, at)%0A%0A%0Adef test_energy():%0A    with t(0):%0A        energy = Energy()%0A        assert energy == 10  # maximum by the default%0A        energy.use()%0A        assert energy == 9%0A        assert energy.recover_in() == 10%0A    with t(1):%0A        assert energy == 9%0A        assert energy.recover_in() == 9%0A    with t(2):%0A        assert energy == 9%0A        assert energy.recover_in() == 8%0A    with t(9):%0A        assert energy == 9%0A        assert energy.recover_in() == 1%0A    with t(10):%0A        assert energy == 10  # recovered fully%0A        assert energy.recover_in() is None%0A    with t(20):%0A        assert energy == 10  # no more recovery%0A        energy.incr(20, limit=False)%0A        assert energy == 30  # extra 20 energy%0A    with t(100):%0A        assert energy == 30%0A%0A%0Adef test_life():%0A    with t(0):%0A        life = Life()%0A        assert life == 100%0A    with t(1):%0A        assert life == 99.9%0A    with t(2):%0A        assert life == 99.8%0A    with t(10):%0A        assert life == 99%0A    with t(100):%0A        assert life == 90%0A        life.recover(1000)%0A        assert life == 100  # limited by the maximum%0A

add test code