def test_process_aggregates_three_systems_two_disp_one_agg(self): """ Process aggregates when there are three systems - two match the display filter and one is cut out by the aggregate. """ f = SafetyAggFilter() f.set_weather(2) self.s.aggfilter.add(f) self.s.dispfilter.add(NameDispFilter('System', False)) sys1 = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys1.addplanet( Planet(1, 'Acid', 'Acid World', 3, 3, 100, 1, 10, 5, MinData(base=3, ))) sys2 = self.s.add_system(2, 'System', 'Beta', 5500, 5500, 'blue dwarf', '') sys2.addplanet( Planet(2, 'Acid', 'Acid World', 1, 1, 100, 1, 5, 0, MinData(radioactive=3, ))) sys3 = self.s.add_system(3, 'Serpentis', 'Gamma', 6000, 6000, 'blue dwarf', '') sys3.addplanet( Planet(3, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData(exotic=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 0) self.assertEqual(self.s.agg_max_value, 24) self.assertEqual(self.s.agg_spread, 24) self.assertEqual(self.s.bio_agg_min_value, 0) self.assertEqual(self.s.bio_agg_max_value, 5) self.assertEqual(self.s.bio_agg_spread, 5)
def test_apply_filters_one_planet_matches(self): """ Tests applying filters when one planet matches the aggregate filter. """ self.s.addplanet( Planet(1, 'Acid', 'Acid World', 4, 4, 100, 1, 10, 5, MinData(base=3, ))) self.s.addplanet( Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 15, 10, MinData( base=1, radioactive=5, ))) f = Filter() saf = SafetyAggFilter() saf.set_tectonics(3, False) f.add(saf) self.s.apply_filters(Filter(), f) self.assertEqual(self.s.highlight, True) self.assertEqual(self.s.mineral_agg.value(), 9) self.assertEqual(self.s.mineral_agg_full.value(), 52) self.assertEqual(self.s.mineral_agg.base, 3) self.assertEqual(self.s.mineral_agg_full.base, 4) self.assertEqual(self.s.mineral_agg.radioactive, 0) self.assertEqual(self.s.mineral_agg_full.radioactive, 5) self.assertEqual(self.s.bio_agg, 10) self.assertEqual(self.s.bio_agg_full, 25) self.assertEqual(self.s.bio_danger_agg, 5) self.assertEqual(self.s.bio_danger_agg_full, 15)
def test_apply_filters_empty_filters(self): """ Tests applying filters when there are none to apply. System should remain highlighted, and all planetary resources included in the aggregate. """ self.s.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) self.s.addplanet( Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 15, 10, MinData( base=1, radioactive=5, ))) self.s.apply_filters(Filter(), Filter()) self.assertEqual(self.s.highlight, True) self.assertEqual(self.s.mineral_agg.value(), 52) self.assertEqual(self.s.mineral_agg_full.value(), 52) self.assertEqual(self.s.mineral_agg.base, 4) self.assertEqual(self.s.mineral_agg_full.base, 4) self.assertEqual(self.s.mineral_agg.radioactive, 5) self.assertEqual(self.s.mineral_agg_full.radioactive, 5) self.assertEqual(self.s.bio_agg, 25) self.assertEqual(self.s.bio_agg_full, 25) self.assertEqual(self.s.bio_danger_agg, 15) self.assertEqual(self.s.bio_danger_agg_full, 15)
def test_process_aggregates_three_systems(self): """ Process aggregates when there are three systems """ sys1 = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys1.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) sys2 = self.s.add_system(2, 'System', 'Beta', 5500, 5500, 'blue dwarf', '') sys2.addplanet( Planet(2, 'Acid', 'Acid World', 1, 1, 100, 1, 5, 0, MinData(radioactive=3, ))) sys3 = self.s.add_system(3, 'System', 'Gamma', 6000, 6000, 'blue dwarf', '') sys3.addplanet( Planet(3, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData(exotic=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 9) self.assertEqual(self.s.agg_max_value, 75) self.assertEqual(self.s.agg_spread, 66) self.assertEqual(self.s.bio_agg_min_value, 0) self.assertEqual(self.s.bio_agg_max_value, 10) self.assertEqual(self.s.bio_agg_spread, 10)
def test_add_planet_type_double(self): """ Tests `add_planet_type` by adding a two planets with the same type """ p = Planet(1, 'Planet I', 'Acid World', 1, 1, 100, 1, 10, 5, MinData()) p2 = Planet(2, 'Planet II', 'Acid World', 1, 1, 100, 1, 10, 5, MinData()) self.s.add_planet_type(p) self.s.add_planet_type(p2) self.assertEqual(len(self.s.planet_types), 1) self.assertIn('Acid', self.s.planet_types)
def test_add_two_planets(self): """ Tests adding two planets """ self.assertEqual(len(self.s.planets), 0) self.s.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData())) self.s.addplanet( Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 0, 0, MinData())) self.assertEqual(len(self.s.planets), 2)
def setUp(self): """ Some objects which we're likely to want in various tests """ self.planet_acid = Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData()) self.planet_chlorine = Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 0, 0, MinData()) self.planet_dust = Planet(3, 'Dust', 'Dust World', 1, 1, 100, 1, 0, 0, MinData()) self.planet_emerald = Planet(4, 'Emerald', 'Emerald World', 1, 1, 100, 1, 0, 0, MinData())
def test_add_planet_type_two_types(self): """ Tests `add_planet_type` by adding a two planets with different types """ p = Planet(1, 'Planet I', 'Acid World', 1, 1, 100, 1, 10, 5, MinData()) p2 = Planet(2, 'Planet II', 'Treasure World', 1, 1, 100, 1, 10, 5, MinData()) self.s.add_planet_type(p) self.s.add_planet_type(p2) self.assertEqual(len(self.s.planet_types), 2) self.assertIn('Acid', self.s.planet_types) self.assertIn('Treasure', self.s.planet_types)
def test_no_match_rev_tectonics(self): """ Tests matching on a planet, with greater-than matches, which fails due to tectonics """ p = Planet(1, 'Acid', 'Acid World', 1, 4, 100, 1, 100, 100, MinData()) self.assertEqual(self.saf_r.approve(p), False)
def test_add_planet_type_single(self): """ Tests `add_planet_type` by adding a single planet """ p = Planet(1, 'Planet I', 'Acid World', 1, 1, 100, 1, 10, 5, MinData()) self.s.add_planet_type(p) self.assertEqual(len(self.s.planet_types), 1) self.assertIn('Acid', self.s.planet_types)
def test_add_planet_type_no_world(self): """ Tests `add_planet_type` by adding a single planet whose type does not include "World". (Are there any planets actually like this?) """ p = Planet(1, 'Planet I', 'StarBase', 1, 1, 100, 1, 10, 5, MinData()) self.s.add_planet_type(p) self.assertEqual(len(self.s.planet_types), 1) self.assertIn('StarBase', self.s.planet_types)
def test_add_one_planet(self): """ Tests adding a single planet """ self.assertEqual(len(self.s.planets), 0) p = Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData()) p2 = self.s.addplanet(p) self.assertEqual(p, p2) self.assertEqual(len(self.s.planets), 1)
def test_bio_intensity_single(self): """ Tests bio intensity for a single system """ sys1 = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys1.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) self.s.process_aggregates() self.assertAlmostEqual(self.s.bio_intensity(sys1), 1)
def test_process_aggregates_two_systems(self): """ Process aggregates when there are two systems """ sys1 = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys1.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) sys2 = self.s.add_system(2, 'System', 'Beta', 5500, 5500, 'blue dwarf', '') sys2.addplanet( Planet(2, 'Acid', 'Acid World', 1, 1, 100, 1, 5, 0, MinData(radioactive=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 9) self.assertEqual(self.s.agg_max_value, 24) self.assertEqual(self.s.agg_spread, 15) self.assertEqual(self.s.bio_agg_min_value, 5) self.assertEqual(self.s.bio_agg_max_value, 10) self.assertEqual(self.s.bio_agg_spread, 5)
def test_process_aggregates_two_planets_both_pass_agg_filter(self): """ Process aggregates when there is one system whose planets all pass the aggregate filters """ f = SafetyAggFilter() self.s.aggfilter.add(f) sys = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) sys.addplanet( Planet(2, 'Acid', 'Acid World', 3, 3, 100, 1, 5, 0, MinData(radioactive=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 33) self.assertEqual(self.s.agg_max_value, 33) self.assertEqual(self.s.agg_spread, 0) self.assertEqual(self.s.bio_agg_min_value, 15) self.assertEqual(self.s.bio_agg_max_value, 15) self.assertEqual(self.s.bio_agg_spread, 0)
def test_bio_intensity_multiple(self): """ Tests bio intensity for multiple systems """ sys1 = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys1.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) sys2 = self.s.add_system(2, 'System', 'Beta', 5500, 5500, 'blue dwarf', '') sys2.addplanet( Planet(2, 'Acid', 'Acid World', 1, 1, 100, 1, 5, 0, MinData(radioactive=3, ))) sys3 = self.s.add_system(3, 'System', 'Gamma', 6000, 6000, 'blue dwarf', '') sys3.addplanet( Planet(3, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData(exotic=3, ))) self.s.process_aggregates() self.assertAlmostEqual(self.s.bio_intensity(sys3), 0) self.assertAlmostEqual(self.s.bio_intensity(sys2), .5) self.assertAlmostEqual(self.s.bio_intensity(sys1), 1)
def test_process_aggregates_one_system(self): """ Process aggregates when there is one system """ sys = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 9) self.assertEqual(self.s.agg_max_value, 9) self.assertEqual(self.s.agg_spread, 0) self.assertEqual(self.s.bio_agg_min_value, 10) self.assertEqual(self.s.bio_agg_max_value, 10) self.assertEqual(self.s.bio_agg_spread, 0)
def test_process_aggregates_one_system_fails_display_filter(self): """ Process aggregates when there is one system which fails the display filters """ self.s.dispfilter.add(NameDispFilter('Yehat', False)) sys = self.s.add_system(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') sys.addplanet( Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 10, 5, MinData(base=3, ))) self.s.process_aggregates() self.assertEqual(self.s.agg_min_value, 0) self.assertEqual(self.s.agg_max_value, 0) self.assertEqual(self.s.agg_spread, 0) self.assertEqual(self.s.bio_agg_min_value, 0) self.assertEqual(self.s.bio_agg_max_value, 0) self.assertEqual(self.s.bio_agg_spread, 0)
def test_apply_filters_dont_highlight(self): """ Tests applying filters when one makes the system not highlight """ self.s.addplanet( Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 15, 10, MinData( base=1, radioactive=5, ))) f = Filter() f.add(TypeDispFilter('Syreen')) self.s.apply_filters(f, Filter()) self.assertEqual(self.s.highlight, False) self.assertEqual(self.s.mineral_agg.value(), 43) self.assertEqual(self.s.mineral_agg_full.value(), 43) self.assertEqual(self.s.bio_agg, 15) self.assertEqual(self.s.bio_agg_full, 15) self.assertEqual(self.s.bio_danger_agg, 10) self.assertEqual(self.s.bio_danger_agg_full, 10)
def test_apply_filters_no_planet_matches(self): """ Tests applying filters when no planets match the aggregate filter """ self.s.addplanet( Planet(2, 'Chlorine', 'Chlorine World', 1, 1, 100, 1, 15, 10, MinData( base=1, radioactive=5, ))) f = Filter() saf = SafetyAggFilter() saf.set_tectonics(3, False) f.add(saf) self.s.apply_filters(Filter(), f) self.assertEqual(self.s.highlight, True) self.assertEqual(self.s.mineral_agg.value(), 0) self.assertEqual(self.s.mineral_agg_full.value(), 43) self.assertEqual(self.s.bio_agg, 0) self.assertEqual(self.s.bio_agg_full, 15) self.assertEqual(self.s.bio_danger_agg, 0) self.assertEqual(self.s.bio_danger_agg_full, 10)
def test_init(self): """ Tests our basic initialization routine """ p = Planet(idnum=1, name='Planet', ptype='Type', tectonics=4, weather=6, temp=200, gravity=2, bio=100, bio_danger=50, mineral=MinData()) self.assertEqual(p.idnum, 1) self.assertEqual(p.name, 'Planet') self.assertEqual(p.ptype, 'Type') self.assertEqual(p.tectonics, 4) self.assertEqual(p.weather, 6) self.assertEqual(p.temp, 200) self.assertEqual(p.gravity, 2) self.assertEqual(p.bio, 100) self.assertEqual(p.bio_danger, 50) self.assertNotEqual(p.mineral, None)
def test_match_rev(self): """ Tests matching on a planet, with greater-than matches. """ p = Planet(1, 'Acid', 'Acid World', 4, 4, 100, 1, 100, 100, MinData()) self.assertEqual(self.saf_r.approve(p), True)
def test_no_match_bio(self): """ Tests matching on a planet, which fails due to bio """ p = Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 500, 500, MinData()) self.assertEqual(self.saf.approve(p), False)
def test_no_match_weather(self): """ Tests matching on a planet, which fails due to weather """ p = Planet(1, 'Acid', 'Acid World', 1, 9, 100, 1, 0, 0, MinData()) self.assertEqual(self.saf.approve(p), False)
def test_match(self): """ Tests matching on a planet. """ p = Planet(1, 'Acid', 'Acid World', 1, 1, 100, 1, 0, 0, MinData()) self.assertEqual(self.saf.approve(p), True)