Initial commit: Plants turn-based battle game
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import engine.collection as collection
|
||||
|
||||
|
||||
class CoinTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._orig = collection._DATA_FILE
|
||||
fd, cls._path = tempfile.mkstemp(suffix=".json")
|
||||
os.close(fd)
|
||||
collection._DATA_FILE = pathlib.Path(cls._path)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
collection._DATA_FILE = cls._orig
|
||||
if os.path.exists(cls._path):
|
||||
os.unlink(cls._path)
|
||||
|
||||
def setUp(self):
|
||||
collection.init_starter_pinwheel("radiant")
|
||||
|
||||
def _backdate(self, seconds, coins=0):
|
||||
data = collection.load()
|
||||
data["coins"] = coins
|
||||
data["coins_accrued_at"] = time.time() - seconds
|
||||
collection.save(data)
|
||||
|
||||
def test_accrue_never_exceeds_cap(self):
|
||||
self._backdate(600, coins=195)
|
||||
self.assertEqual(collection.accrue_coins(), 5) # only up to the cap
|
||||
self.assertEqual(collection.available_coins(), collection.COIN_CAP)
|
||||
|
||||
def test_no_generation_while_at_cap(self):
|
||||
self._backdate(120, coins=collection.COIN_CAP)
|
||||
self.assertEqual(collection.accrue_coins(), 0)
|
||||
self.assertEqual(collection.available_coins(), collection.COIN_CAP)
|
||||
|
||||
def test_generation_resumes_after_spending(self):
|
||||
self._backdate(61, coins=150)
|
||||
self.assertEqual(collection.accrue_coins(), 1)
|
||||
self.assertEqual(collection.available_coins(), 151)
|
||||
|
||||
def test_add_coins_respects_cap(self):
|
||||
data = collection.load()
|
||||
data["coins"] = collection.COIN_CAP - 1
|
||||
collection.save(data)
|
||||
collection.add_coins(10)
|
||||
self.assertEqual(collection.available_coins(), collection.COIN_CAP)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user