Mercurial > sypikslang
diff gamelib/tests/test_lab.py @ 21:bdc6bfc34ef2
Serialise lab data.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 06 May 2012 18:34:28 +0200 |
parents | 718d1ec382f7 |
children | 23720d0fd9a0 |
line wrap: on
line diff
--- a/gamelib/tests/test_lab.py Sun May 06 18:12:51 2012 +0200 +++ b/gamelib/tests/test_lab.py Sun May 06 18:34:28 2012 +0200 @@ -4,6 +4,15 @@ from gamelib import research, products +LAB_DATA = { + 'science': { + 'research.Robotics': 1, + 'research.Rocketry': 2, + 'research.Tesla': 3, + }, + } + + class TestLab(TestCase): def test_new_lab(self): all_sciences = set() @@ -17,22 +26,23 @@ self.assertTrue(len(all_sciences) > 3) def test_find_new_products(self): - lab = Lab({ - 'science': { - 'research.Tesla': 3, - } - }) + lab = Lab(LAB_DATA) new_products = lab.find_new_products(None) self.assertTrue(products.TeslaTank in new_products) self.assertTrue(products.DoomsdayVirus not in new_products) def test_find_new_research(self): - lab = Lab({ - 'science': { - 'research.Robotics': 1, - 'research.Rocketry': 2, - } - }) + lab = Lab(LAB_DATA) new_research = lab.find_new_research() self.assertTrue(research.Space in new_research) self.assertTrue(research.ArtificialIntelligence not in new_research) + + def test_save_data(self): + # Check that we save what we loaded. + lab = Lab(LAB_DATA) + self.assertEqual(LAB_DATA, lab.save_data()) + # Add a product and check that it gets saved as well. + lab._gain_science(products.LightningGun()) + new_science = dict( + LAB_DATA['science'].items() + [('products.LightningGun', 0)]) + self.assertEqual({'science': new_science}, lab.save_data())