Mercurial > sypikslang
annotate 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 |
rev | line source |
---|---|
8 | 1 from unittest import TestCase |
2 | |
3 from gamelib.lab import Lab | |
14 | 4 from gamelib import research, products |
8 | 5 |
6 | |
21 | 7 LAB_DATA = { |
8 'science': { | |
9 'research.Robotics': 1, | |
10 'research.Rocketry': 2, | |
11 'research.Tesla': 3, | |
12 }, | |
13 } | |
14 | |
15 | |
8 | 16 class TestLab(TestCase): |
20 | 17 def test_new_lab(self): |
18 all_sciences = set() | |
19 for _ in range(10): | |
20 lab = Lab() | |
21 research_areas = [r for r in lab.science | |
22 if isinstance(r, research.ResearchArea)] | |
23 self.assertEqual(3, len(research_areas)) | |
24 for science in research_areas: | |
25 all_sciences.add(type(science)) | |
26 self.assertTrue(len(all_sciences) > 3) | |
14 | 27 |
8 | 28 def test_find_new_products(self): |
21 | 29 lab = Lab(LAB_DATA) |
20 | 30 new_products = lab.find_new_products(None) |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
31 self.assertTrue(products.TeslaTank in new_products) |
14 | 32 self.assertTrue(products.DoomsdayVirus not in new_products) |
8 | 33 |
34 def test_find_new_research(self): | |
21 | 35 lab = Lab(LAB_DATA) |
20 | 36 new_research = lab.find_new_research() |
17
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
37 self.assertTrue(research.Space in new_research) |
10d3db1f1e08
Set up initial research and rework breakthroughs.
Jeremy Thurgood <firxen@gmail.com>
parents:
14
diff
changeset
|
38 self.assertTrue(research.ArtificialIntelligence not in new_research) |
21 | 39 |
40 def test_save_data(self): | |
41 # Check that we save what we loaded. | |
42 lab = Lab(LAB_DATA) | |
43 self.assertEqual(LAB_DATA, lab.save_data()) | |
44 # Add a product and check that it gets saved as well. | |
45 lab._gain_science(products.LightningGun()) | |
46 new_science = dict( | |
47 LAB_DATA['science'].items() + [('products.LightningGun', 0)]) | |
48 self.assertEqual({'science': new_science}, lab.save_data()) |