def test_match_substring(self): """ Tests matching a substring type """ tdf = TypeDispFilter('Acid') system = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') system.addplanet(self.planet_acid) self.assertEqual(tdf.approve(system), True)
def test_no_match(self): """ Tests matching a system which doesn't match """ tdf = TypeDispFilter('Acid World') system = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') system.addplanet(self.planet_chlorine) self.assertEqual(tdf.approve(system), False)
def test_approve_two_matches(self): """ Tests approving a system with two filters which both match """ s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') s2 = System(2, 'System', 'Beta', 5100, 5100, 'red dwarf', '') self.f.add(NameDispFilter('alpha system', False)) self.f.add(ProxDispFilter(s2, 500)) self.assertEqual(self.f.approve(s), True)
def test_approve_two_matches_first_fails(self): """ Tests approving a system with two filters in which the first one fails. """ s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') s2 = System(2, 'System', 'Beta', 5100, 5100, 'red dwarf', '') self.f.add(NameDispFilter('ur-quan', False)) self.f.add(ProxDispFilter(s2, 500)) self.assertEqual(self.f.approve(s), False)
def test_no_match_empty(self): """ Tests matching an empty system (should fail) """ tdf = TypeDispFilter('Acid World') system = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') self.assertEqual(tdf.approve(system), False)
def test_match_full_wrong_prefix(self): """ Tests matching a full system name, with the location prefix but a wrong one. """ system = System(1, 'System Name', 'Beta', 5000, 5000, 'blue dwarf', '') ndf = NameDispFilter('Alpha System Name', False) self.assertEqual(ndf.approve(system), False)
def test_init_no_position(self): """ Tests our basic initialization routine without a `position` argument (or, more accurately, with an empty string for `position`) """ s = System(1, 'System', '', 5000, 5000, 'blue dwarf', 'hint') self.assertEqual(s.fullname, 'System')
def test_match_lc_uc(self): """ Tests matching a lowercase system name with uppercase search """ system = System(1, 'system', 'Alpha', 5000, 5000, 'blue dwarf', '') ndf = NameDispFilter('SYSTEM', False) self.assertEqual(ndf.approve(system), True)
def test_approve_single_match(self): """ Tests approving a system with a single filter which matches """ s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') self.f.add(NameDispFilter('alpha system', False)) self.assertEqual(self.f.approve(s), True)
def test_case_mismatch(self): """ Tests a case mismatch """ system = System(1, 'Constellation', 'Alpha', 5000, 5000, 'blue dwarf', '') cdf = ConstDispFilter('constellation') self.assertEqual(cdf.approve(system), False)
def test_match_extra(self): """ Tests matching based on extra text """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', 'Zoq-Fot-Pik Homeworld') ndf = NameDispFilter('zoq', True) self.assertEqual(ndf.approve(system), True)
def test_match_substring(self): """ Tests matching a substring of a system name """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', '') ndf = NameDispFilter('Stem', False) self.assertEqual(ndf.approve(system), True)
def test_match_extra_lc_uc(self): """ Tests matching extra text with lowercase extra and uppercase search """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', 'extra') ndf = NameDispFilter('EXTRA', True) self.assertEqual(ndf.approve(system), True)
def test_no_match(self): """ Tests matching a full system name where it doesn't work """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', '') cdf = ConstDispFilter('Alpha System Name') self.assertEqual(cdf.approve(system), False)
def test_no_match(self): """ Attempting to match a system which fails """ system = System(1, 'Zoq-Fot-Pik', 'Alpha', 5000, 5000, 'blue dwarf', '') ndf = NameDispFilter('Ur-Quan', False) self.assertEqual(ndf.approve(system), False)
def test_match(self): """ Tests matching a full system name """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', '') cdf = ConstDispFilter('System Name') self.assertEqual(cdf.approve(system), True)
def test_add_two_filters(self): """ Tests adding two new filters to the chain """ s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') self.f.add(NameDispFilter('Hello', False)) self.f.add(ProxDispFilter(s, 500)) self.assertEqual(self.f.filtering(), True)
def test_match_multiple(self): """ Tests matching a system with more than one planet """ tdf = TypeDispFilter('Acid World') system = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') system.addplanet(self.planet_dust) system.addplanet(self.planet_chlorine) system.addplanet(self.planet_acid) self.assertEqual(tdf.approve(system), True)
def test_no_match_extra(self): """ Tests matching a full system name where it doesn't work, even though the extra text might do the trick """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', 'Alpha System Name') cdf = ConstDispFilter('Alpha System Name') self.assertEqual(cdf.approve(system), False)
def setUp(self): """ Some objects which we're likely to want in various tests """ self.system_center = System(1, 'Center', 'Alpha', 5000, 5000, 'white dwarf', '') self.pdf = ProxDispFilter(self.system_center, 100) self.quasi_center = Quasispace(5000, 5000, 5000, 5000, 'X') self.qpdf = ProxDispFilter(self.quasi_center, 100)
def test_match_extra_without_flag(self): """ Tests matching based on extra text, but without the extra text being a valid source """ system = System(1, 'System Name', 'Alpha', 5000, 5000, 'blue dwarf', 'Zoq-Fot-Pik Homeworld') ndf = NameDispFilter('zoq', False) self.assertEqual(ndf.approve(system), False)
def test_reset(self): """ Tests resetting the filter """ s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', '') self.f.add(NameDispFilter('Hello', False)) self.f.add(ProxDispFilter(s, 500)) self.assertEqual(self.f.filtering(), True) self.f.reset() self.assertEqual(self.f.filtering(), False)
def test_distance_diagonal(self): """ Tests computing the distance to another system at a diagonal """ s2 = System(2, 'System', 'Beta', 3000, 7000, 'blue dwarf', '') self.assertAlmostEqual(self.s.distance_to(s2), 282.84, 2)
def test_match_close(self): """ Test matching a close system """ system_close = System(2, 'Close', 'Alpha', 5100, 5100, 'red dwarf', '') self.assertEqual(self.pdf.approve(system_close), True)
def test_distance_close(self): """ Tests computing the distance to another system close by """ s2 = System(2, 'System', 'Beta', 5500, 5000, 'blue dwarf', '') self.assertAlmostEqual(self.s.distance_to(s2), 50)
def setUp(self): """ Some vars we might need on (nearly) every test """ self.s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', 'hint')
class SystemTests(unittest.TestCase): """ Tests for our `System` class. This is the class which describes a system and holds a bunch of Planet objects. """ def setUp(self): """ Some vars we might need on (nearly) every test """ self.s = System(1, 'System', 'Alpha', 5000, 5000, 'blue dwarf', 'hint') def test_init(self): """ Tests our basic initialization routine """ self.assertEqual(self.s.idnum, 1) self.assertEqual(self.s.name, 'System') self.assertEqual(self.s.position, 'Alpha') self.assertEqual(self.s.x, 5000) self.assertEqual(self.s.y, 5000) self.assertEqual(self.s.stype, 'blue dwarf') self.assertEqual(self.s.extra, 'hint') self.assertEqual(self.s.fullname, 'Alpha System') self.assertEqual(self.s.is_quasispace, False) def test_init_no_position(self): """ Tests our basic initialization routine without a `position` argument (or, more accurately, with an empty string for `position`) """ s = System(1, 'System', '', 5000, 5000, 'blue dwarf', 'hint') self.assertEqual(s.fullname, 'System') 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_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 test_distance_to_self(self): """ Tests computing the distance to ourself """ self.assertAlmostEqual(self.s.distance_to(self.s), 0) def test_distance_close(self): """ Tests computing the distance to another system close by """ s2 = System(2, 'System', 'Beta', 5500, 5000, 'blue dwarf', '') self.assertAlmostEqual(self.s.distance_to(s2), 50) def test_distance_diagonal(self): """ Tests computing the distance to another system at a diagonal """ s2 = System(2, 'System', 'Beta', 3000, 7000, 'blue dwarf', '') self.assertAlmostEqual(self.s.distance_to(s2), 282.84, 2) 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_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_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_quasi_not_match_far(self): """ Test not matching a far system, with quasispace origin """ system_far = System(3, 'Far', 'Alpha', 9000, 9000, 'blue dwarf', '') self.assertEqual(self.qpdf.approve(system_far), False)
def test_quasi_match_close(self): """ Test matching a close system, with quasispace origin """ system_close = System(2, 'Close', 'Alpha', 5100, 5100, 'red dwarf', '') self.assertEqual(self.qpdf.approve(system_close), True)
def test_not_match_far(self): """ Test not matching a far system """ system_far = System(3, 'Far', 'Alpha', 9000, 9000, 'blue dwarf', '') self.assertEqual(self.pdf.approve(system_far), False)