def test_to_good(self): """Going to Good""" app = Labyrinth(1, 1, self.set_up_test_scenario) self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 3) app.map["Gulf States"].make_poor() self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 4) app.map["Gulf States"].make_fair() app.map["Gulf States"].make_neutral() self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 4)
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["114"].playEvent("US", app) self.assertTrue("GTMO" in app.lapsing) self.assertTrue(app.prestige != 7) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["114"].playEvent("Jihadist", app) self.assertTrue("GTMO" in app.lapsing) self.assertTrue(app.prestige != 7)
def test_playable(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertFalse(app.deck["109"].playable("US", app, True)) self.assertFalse(app.deck["109"].playable("Jihadist", app, False)) app.testCountry("Pakistan") app.map["Pakistan"].activeCells = 2 self.assertFalse(app.deck["109"].playable("US", app, True)) self.assertFalse(app.deck["109"].playable("Jihadist", app, False)) app.map["Pakistan"].regimeChange = 1 self.assertTrue(app.deck["109"].playable("US", app, True)) self.assertTrue(app.deck["109"].playable("Jihadist", app, False))
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["101"].playEvent("US", app) self.assertEqual(app.prestige, 8) self.assertEqual(app.map["Serbia"].posture, "Soft") app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.map["United States"].posture = "Soft" app.deck["101"].playEvent("Jihadist", app) self.assertEqual(app.prestige, 8) self.assertEqual(app.map["Serbia"].posture, "Hard")
def test_playable(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertFalse(app.deck["108"].playable("US", app, True)) self.assertFalse(app.deck["108"].playable("Jihadist", app, False)) app.testCountry("Pakistan") app.map["Pakistan"].activeCells = 1 self.assertTrue(app.deck["108"].playable("US", app, True)) self.assertTrue(app.deck["108"].playable("Jihadist", app, False)) app.markers.append("Benazir Bhutto") self.assertFalse(app.deck["108"].playable("US", app, True)) self.assertFalse(app.deck["108"].playable("Jihadist", app, False))
def _assert_adjust_posture(self, user_input, expected_posture, expected_successful=True): # Set up non_muslim_country = "France" # Only these have a posture app = Labyrinth(1, 1, self.set_up_test_scenario, test_user_input=[user_input]) self.assertEqual(app.map[non_muslim_country].posture, "") # means "Untested" # Invoke successful = app.adjustCountryPosture(non_muslim_country) # Check self.assertEqual(successful, expected_successful) self.assertEqual(app.map[non_muslim_country].posture, expected_posture)
def test_schengen_countries(self): # Set up app = Labyrinth(1, 1, self.set_up_test_scenario) # Invoke schengen_countries = app.names_of_countries(lambda c: c.schengen) # Check self.assertEqual(schengen_countries, [ 'France', 'Italy', 'Germany', 'Spain', 'Scandinavia', 'Eastern Europe', 'Benelux' ])
def test_num_disruptable(self): # Set up app = Labyrinth(1, 1) app.map["Canada"].sleeperCells = 1 app.map["Iraq"].sleeperCells = 1 app.map["Iraq"].make_ally() app.map["Jordan"].sleeperCells = 1 app.map["Jordan"].troopCubes = 2 app.map["Libya"].sleeperCells = 1 app.map["Libya"].troopCubes = 1 # Should not be enough # Invoke & assert self.assertEqual(app.num_disruptable(), 3)
def test_playable(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertFalse(app.deck["106"].playable("US", app, True)) self.assertFalse(app.deck["106"].playable("Jihadist", app, False)) app.testCountry("Iraq") app.map["Iraq"].sleeperCells = 1 self.assertFalse(app.deck["106"].playable("US", app, True)) self.assertFalse(app.deck["106"].playable("Jihadist", app, False)) app.map["Iraq"].troopCubes = 1 self.assertTrue(app.deck["106"].playable("US", app, True)) self.assertTrue(app.deck["106"].playable("Jihadist", app, False)) app.map["Iraq"].sleeperCells = 0 self.assertFalse(app.deck["106"].playable("US", app, True)) self.assertFalse(app.deck["106"].playable("Jihadist", app, False))
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario, ["Iraq"]) app.testCountry("Iraq") app.map["Iraq"].sleeperCells = 1 app.deck["105"].playEvent("US", app) self.assertEqual(app.map["Iraq"].sleeperCells, 0) app = Labyrinth(1, 1, self.set_up_blank_test_scenario, ["Yemen"]) app.testCountry("Iraq") app.map["Iraq"].sleeperCells = 1 app.testCountry("Yemen") app.map["Yemen"].sleeperCells = 1 app.deck["105"].playEvent("US", app) self.assertEqual(app.map["Yemen"].sleeperCells, 0) app.deck["105"].playEvent("Jihadist", app)
def test_travel_second_box(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.map["Afghanistan"].make_poor() app.map["Afghanistan"].troopCubes = 1 app.map["Afghanistan"].sleeperCells = 4 dest = app.travelDestinations(1) self.assertEqual(dest, ["Afghanistan"]) app.map["Gulf States"].make_poor() app.map["Gulf States"].besieged = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Gulf States"]) dest = app.travelDestinations(2) self.assertEqual(dest, ["Gulf States", "Afghanistan"])
def test_us_hard_and_one_unmarked_schengen(self): # Set up app = Labyrinth(1, 1, self.set_up_test_scenario) app.map["United States"].posture = "Hard" schengen_countries = self.schengen_countries(app) for schengen_country in schengen_countries[1:]: schengen_country.posture = "Anything" unmarked_country = schengen_countries[0] unmarked_country.posture = "" # Invoke destinations = app.travelDestinationsSchengenVisas() # Check expected_country = unmarked_country.name self.assertEqual(destinations, [expected_country, expected_country])
def test_alert(self): app = Labyrinth(1, 1, self.set_up_test_scenario) self.assertEqual(app.map["Iraq"].plots, 2) app.handleAlert("Iraq") self.assertEqual(app.map["Iraq"].plots, 1) app.handleAlert("Iraq") self.assertEqual(app.map["Iraq"].plots, 0) app.handleAlert("Iraq") self.assertEqual(app.map["Iraq"].plots, 0)
def test_is_adjacent(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertTrue(app.isAdjacent("Iran", "Iraq")) self.assertTrue(app.isAdjacent("Germany", "Spain")) self.assertTrue(app.isAdjacent("Libya", "Italy")) self.assertTrue(app.isAdjacent("Benelux", "Russia")) self.assertTrue(app.isAdjacent("Lebanon", "France")) self.assertFalse(app.isAdjacent("United States", "Lebanon"))
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["119"].playEvent("US", app) self.assertTrue(app.map["Yemen"].is_governed()) self.assertTrue(app.map["Yemen"].is_ally()) self.assertEqual(app.map["Yemen"].aid, 1) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.map["Yemen"].make_islamist_rule() app.map["Yemen"].make_neutral() app.deck["119"].playEvent("US", app) self.assertTrue(app.map["Yemen"].is_governed()) self.assertTrue(app.map["Yemen"].is_neutral()) self.assertEqual(app.map["Yemen"].aid, 0) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["119"].playEvent("Jihadist", app) self.assertTrue(app.map["Yemen"].is_governed()) self.assertTrue(app.map["Yemen"].is_adversary()) self.assertEqual(app.map["Yemen"].besieged, 1)
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Iraq") app.map["Iraq"].troopCubes = 2 app.deck["110"].playEvent("US", app) self.assertEqual(app.prestige, 10) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Iraq") app.map["Iraq"].troopCubes = 2 app.deck["110"].playEvent("Jihadist", app) self.assertEqual(app.map["Iraq"].totalCells(True), 3) self.assertEqual(app.map["Iraq"].plots, 1)
def test_travel_first_box(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.map["Gulf States"].make_poor() app.map["Gulf States"].besieged = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Gulf States"]) app.map["Gulf States"].besieged = 0 app.map["Gulf States"].aid = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Gulf States"]) app.map["Gulf States"].aid = 0 app.map["Gulf States"].regimeChange = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Gulf States"]) app.map["Gulf States"].make_islamist_rule() app.map["Afghanistan"].make_poor() app.map["Afghanistan"].besieged = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Afghanistan"]) app.map["Gulf States"].make_poor() dest = app.travelDestinations(1) self.assertEqual(dest, ["Gulf States"]) app.map["Iraq"].make_poor() app.map["Iraq"].aid = 1 iraqCount = 0 gulfCount = 0 for i in range(100): dest = app.travelDestinations(1) if dest == ["Gulf States"]: gulfCount += 1 elif dest == ["Iraq"]: iraqCount += 1 self.assertTrue(dest == ["Gulf States"] or dest == ["Iraq"]) self.assertTrue(iraqCount > 0) self.assertTrue(gulfCount > 0) app.map["Pakistan"].make_poor() app.map["Pakistan"].aid = 1 dest = app.travelDestinations(1) self.assertEqual(dest, ["Pakistan"])
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["118"].playEvent("US", app) self.assertEqual(app.countryResources("Saudi Arabia"), 4) app = Labyrinth(1, 1, self.set_up_blank_test_scenario, ["y"]) app.deck["118"].playEvent("Jihadist", app) self.assertEqual(app.countryResources("Saudi Arabia"), 4) app.deck["118"].playEvent("US", app) self.assertEqual(app.countryResources("Saudi Arabia"), 5)
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["112"].playEvent("US", app) self.assertEqual(app.funding, 1) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["112"].playEvent("Jihadist", app) self.assertEqual(app.prestige, 5) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Iraq") app.map["Iraq"].make_islamist_rule() app.deck["112"].playEvent("Jihadist", app) self.assertEqual(app.prestige, 3)
def test_reassessment(self): app = Labyrinth(1, 1, self.set_up_test_scenario) self.assertEqual(app.map["United States"].posture, "Hard") app.handleReassessment() self.assertEqual(app.map["United States"].posture, "Soft") app.handleReassessment() self.assertEqual(app.map["United States"].posture, "Hard")
def test_cell_placement_removes_cadre(self): # Set up mock_randomizer = mock(Randomizer()) app = Labyrinth(1, 1, self.set_up_test_scenario, randomizer=mock_randomizer) country_name = "Iraq" when(mock_randomizer).pick_one(app.map.keys()).thenReturn(country_name) country = app.map[country_name] country.cadre = 1 sleepers_before = country.sleeperCells # Invoke app.handleRadicalization(1) # Assert sleepers_after = country.sleeperCells self.assertEqual(sleepers_after, sleepers_before + 1, "Radicalization should place a sleeper") self.assertEqual(country.cadre, 0, "Cell placement should have removed the cadre")
def test_playable(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertTrue(app.deck["116"].playable("Jihadist", app, False)) self.assertFalse(app.deck["116"].playable("US", app, True)) app.testCountry("Iraq") app.map["Iraq"].make_ally() app.map["Iraq"].plots = 1 self.assertTrue(app.deck["116"].playable("US", app, True)) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) self.assertTrue(app.deck["116"].playable("Jihadist", app, False)) self.assertFalse(app.deck["116"].playable("US", app, True)) app.testCountry("Canada") app.map["Canada"].plots = 1 self.assertTrue(app.deck["116"].playable("US", app, True))
def test_gwot_penalty(self): """GWOT Penalty""" app = Labyrinth(1, 1, self.set_up_test_scenario) self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 3) app.map["United States"].posture = "Soft" self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 2) app.map["Canada"].posture = "Hard" self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 1) app.map["France"].posture = "Hard" self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 0) app.map["Germany"].posture = "Hard" self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 0)
def test_us_hard_and_multiple_unmarked_schengens(self): # Set up mock_randomizer = mock(Randomizer()) app = Labyrinth(1, 1, self.set_up_test_scenario, randomizer=mock_randomizer) schengen_countries = self.schengen_countries(app) schengen_country_names = [ country.name for country in schengen_countries ] chosen_countries = ['c1', 'c2'] when(mock_randomizer).pick( 2, schengen_country_names).thenReturn(chosen_countries) app.map["United States"].posture = "Hard" for country in schengen_countries: country.posture = "" # Invoke destinations = app.travelDestinationsSchengenVisas() # Check self.assertEqual(destinations, chosen_countries)
def test_travel_fourth_box(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.map["United States"].posture = "Hard" app.map["Canada"].posture = "Hard" app.map["United Kingdom"].posture = "Hard" app.map["Serbia"].posture = "Hard" app.map["India"].posture = "Hard" app.map["Scandinavia"].posture = "Hard" app.map["Eastern Europe"].posture = "Hard" app.map["Benelux"].posture = "Hard" app.map["Germany"].posture = "Hard" app.map["France"].posture = "Hard" app.map["Italy"].posture = "Hard" app.map["Spain"].posture = "Hard" app.map["Russia"].posture = "Hard" app.map["Caucasus"].posture = "Hard" app.map["China"].posture = "Hard" app.map["Kenya/Tanzania"].posture = "Hard" app.map["Thailand"].posture = "Hard" dest = app.travelDestinations(1) self.assertEqual(dest, ["Philippines"])
class CountryDistanceTest(LabyrinthTestCase): """Test countryDistance""" __app = None def setUp(self): self.__app = Labyrinth(1, 1, self.set_up_blank_test_scenario) def assert_distance(self, from_country, to_country, expected_distance): self.assertEqual(self.__app.countryDistance(from_country, to_country), expected_distance) def test_distance(self): self.assert_distance("Iran", "Iran", 0) self.assert_distance("Iran", "Iraq", 1) self.assert_distance("Iran", "Sudan", 4) self.assert_distance("Thailand", "United States", 2) self.assert_distance("Russia", "Morocco", 2)
def test_adjacent_countries(self): """Adjacent countries Ally Good""" app = Labyrinth(1, 1, self.set_up_test_scenario) self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 3) app.map['Pakistan'].make_good() app.map['Pakistan'].make_neutral() self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 3) app.map['Pakistan'].make_ally() self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 4) app.map['Iraq'].make_good() app.map['Iraq'].make_ally() self.assertEqual(app.modifiedWoIRoll(3, "Gulf States"), 4)
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Pakistan") app.map["Pakistan"].sleeperCells = 1 app.map["Pakistan"].make_good() app.deck["108"].playEvent("US", app) self.assertCells(app, "Pakistan", 0, True) self.assertTrue(app.map["Pakistan"].is_poor()) self.assertTrue(app.map["Pakistan"].is_ally()) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Pakistan") app.map["Pakistan"].sleeperCells = 3 app.map["Pakistan"].make_islamist_rule() app.map["Pakistan"].make_adversary() app.deck["108"].playEvent("Jihadist", app) self.assertCells(app, "Pakistan", 2, True) self.assertTrue(app.map["Pakistan"].is_poor()) self.assertTrue(app.map["Pakistan"].is_ally())
def test_event(self): app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.deck["102"].playEvent("US", app) self.assertTrue(app.map["Central Asia"].is_neutral()) app = Labyrinth(1, 1, self.set_up_blank_test_scenario) app.testCountry("Central Asia") app.map["Central Asia"].make_good() app.map["Central Asia"].make_ally() app.deck["102"].playEvent("Jihadist", app) self.assertFalse(app.map["Central Asia"].is_good()) self.assertTrue(app.map["Central Asia"].is_neutral())
def test_withdraw(self): app = Labyrinth(1, 1, self.set_up_test_scenario_2) app.map["United States"].posture = "Soft" self.assertTrue(app.map["Afghanistan"].is_good()) self.assertTrue(app.map["Afghanistan"].is_ally()) self.assertEqual(app.map["Afghanistan"].troops(), 6) self.assertEqual(app.map["Afghanistan"].aid, 1) self.assertEqual(app.map["Afghanistan"].besieged, 0) self.assertEqual(app.map["Saudi Arabia"].troops(), 2) self.assertEqual(app.prestige, 7) self.assertEqual(app.troops, 3) prestigeRolls = (5, 2, 5) app.handleWithdraw("Afghanistan", "Saudi Arabia", 4, prestigeRolls) self.assertTrue(app.map["Afghanistan"].is_good()) self.assertTrue(app.map["Afghanistan"].is_ally()) self.assertEqual(app.map["Afghanistan"].troops(), 2) self.assertEqual(app.map["Afghanistan"].aid, 0) self.assertEqual(app.map["Afghanistan"].besieged, 1) self.assertEqual(app.map["Saudi Arabia"].troops(), 6) self.assertEqual(app.prestige, 9) self.assertEqual(app.troops, 3) app = Labyrinth(1, 1, self.set_up_test_scenario_2) app.map["United States"].posture = "Soft" self.assertTrue(app.map["Afghanistan"].is_good()) self.assertTrue(app.map["Afghanistan"].is_ally()) self.assertEqual(app.map["Afghanistan"].troops(), 6) self.assertEqual(app.map["Afghanistan"].aid, 1) self.assertEqual(app.map["Afghanistan"].besieged, 0) self.assertEqual(app.map["Saudi Arabia"].troops(), 2) self.assertEqual(app.prestige, 7) self.assertEqual(app.troops, 3) prestigeRolls = (2, 3, 5) app.handleWithdraw("Afghanistan", "track", 5, prestigeRolls) self.assertTrue(app.map["Afghanistan"].is_good()) self.assertTrue(app.map["Afghanistan"].is_ally()) self.assertEqual(app.map["Afghanistan"].troops(), 1) self.assertEqual(app.map["Afghanistan"].aid, 0) self.assertEqual(app.map["Afghanistan"].besieged, 1) self.assertEqual(app.map["Saudi Arabia"].troops(), 2) self.assertEqual(app.prestige, 4) self.assertEqual(app.troops, 8)