コード例 #1
0
    def test_no_countries_have_plots_at_first(self):
        # Set up
        app = Labyrinth(1, 1)

        # Invoke
        plot_countries = app.get_plot_countries()

        # Check
        self.assertEqual([], plot_countries)
コード例 #2
0
    def test_iran_with_nothing_in_it(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = app.get_country("Iran")

        # Invoke
        summary = iran.summary()

        # Check
        self.assertEqual(summary, "Iran, Fair")
コード例 #3
0
 def test_reassessment(self):
     app = Labyrinth(1, 1, self.set_up_test_scenario)
     self.assertEqual(app.us_posture(), HARD)
     app.toggle_us_posture()
     self.assertEqual(app.us_posture(), SOFT)
     app.toggle_us_posture()
     self.assertEqual(app.us_posture(), HARD)
コード例 #4
0
    def test_country_without_nato_has_no_extra_troops(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = app.get_country("Iran")
        iran.change_troops(2)

        # Invoke
        troops = iran.troops()

        # Check
        self.assertEqual(2, troops)
コード例 #5
0
    def test_non_muslim_country_with_no_markers(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        israel = app.get_country("Israel")
        israel.plots = 2

        # Invoke
        summary = israel.summary()

        # Check
        self.assertEqual(summary, "Israel - Posture: Hard\n    Plots: 2")
コード例 #6
0
    def test_should_have_minimal_choice_with_one_ops(self):
        # Set up
        app = Labyrinth(1, 1)

        # Invoke
        prompt = app.get_us_prompt_to_spend_ops(4)  # Moro talks

        # Check
        self.assertEqual(
            prompt,
            "1 Ops available. Use one of: deploy, disrupt, reserves, war_of_ideas"
        )
コード例 #7
0
    def test_troops_disrupting_cadre_increases_prestige(self):
        # Set up
        app = Labyrinth(1, 1, test_user_input=["Egypt"])
        prestige_before = app.prestige
        app.get_country("Egypt").cadre = 1
        app.get_country("Egypt").troopCubes = 2

        # Invoke
        app.disrupt_cells_or_cadre()

        # Check
        self.assertEqual(app.prestige, prestige_before + 1)
コード例 #8
0
    def test_iran_with_things_in_it(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = app.get_country("Iran")
        iran.plots = 3
        iran.activeCells = 4

        # Invoke
        summary = iran.summary()

        # Check
        self.assertEqual(summary, "Iran, Fair\n    Active: 4, Plots: 3")
コード例 #9
0
    def test_scenario_1_makes_afghanistan_islamist_rule_adversary(self):
        # Set up
        app = Labyrinth(1, 1)
        afghanistan = app.get_country("Afghanistan")

        # Invoke
        alignment = afghanistan.alignment()
        governance = afghanistan.get_governance()

        # Check
        self.assertEqual(ADVERSARY, alignment)
        self.assertEqual(ISLAMIST_RULE, governance)
コード例 #10
0
    def test_should_be_able_to_do_anything_with_three_ops(self):
        # Set up
        app = Labyrinth(1, 1)

        # Invoke
        prompt = app.get_us_prompt_to_spend_ops(82)  # Jihadist Videos

        # Check
        self.assertEqual(
            prompt,
            "3 Ops available. Use one of: alert, deploy, disrupt, reassessment, regime_change,"
            " reserves, war_of_ideas, withdraw")
コード例 #11
0
    def test_country_with_nato_has_two_extra_troops(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = app.get_country("Iran")
        iran.change_troops(2)
        iran.markers.append("NATO")

        # Invoke
        troops = iran.troops()

        # Check
        self.assertEqual(4, troops)
コード例 #12
0
    def test_two_countries_have_plots(self):
        # Set up
        app = Labyrinth(1, 1)
        actual_plot_countries = ["China", "Italy"]
        for country_name in actual_plot_countries:
            app.get_country(country_name).plots = 2

        # Invoke
        plot_countries = [c.name for c in app.get_plot_countries()]

        # Check
        plot_countries.sort()
        self.assertEqual(actual_plot_countries, plot_countries)
コード例 #13
0
    def test_us_hard_and_one_unmarked_schengen(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_test_scenario)
        app.set_posture("United States", HARD)
        schengen_countries = self.schengen_countries(app)
        for schengen_country in schengen_countries[1:]:
            schengen_country.make_soft()
        unmarked_country = schengen_countries[0]
        unmarked_country.remove_posture()

        # Invoke
        destinations = app.travel_destinations_schengen_visas()

        # Check
        expected_country = unmarked_country.name
        self.assertEqual(destinations, [expected_country, expected_country])
コード例 #14
0
    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
        expected_names = [
            'France', 'Scandinavia', 'Benelux', 'Italy', 'Germany', 'Spain',
            'Eastern Europe'
        ]
        self.assertEqual(len(expected_names), len(schengen_countries))
        for expected_name in expected_names:
            self.assertTrue(expected_name in schengen_countries,
                            "Could not find '%s'" % expected_name)
コード例 #15
0
    def test_num_disruptable(self):
        # Set up
        app = Labyrinth(1, 1)
        app.get_country("Canada").sleeperCells = 1
        app.get_country("Iraq").sleeperCells = 1
        app.get_country("Iraq").make_ally()
        app.get_country("Jordan").sleeperCells = 1
        app.get_country("Jordan").troopCubes = 2
        app.get_country("Libya").sleeperCells = 1
        app.get_country("Libya").troopCubes = 1  # Should not be enough

        # Invoke & assert
        self.assertEqual(app.num_disruptable(), 3)
コード例 #16
0
 def test_alert_reduces_plot_count_by_one(self):
     app = Labyrinth(1, 1, self.set_up_test_scenario)
     iraq = app.map.get("Iraq")
     self.assertEqual(iraq.plots, 2)
     app.alert_plot("Iraq")
     self.assertEqual(iraq.plots, 1)
     app.alert_plot("Iraq")
     self.assertEqual(iraq.plots, 0)
     with self.assertRaises(AssertionError):
         app.alert_plot("Iraq")
コード例 #17
0
ファイル: test_summary.py プロジェクト: andrewswan/lwotai
    def test_summary(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_test_scenario)
        app.play_us_card(116)  # 3 ops
        app.deploy_reserves()

        # Invoke
        summary = app.get_summary()

        # Assert
        self.assertEqual(summary, [
            'Jihadist Ideology: Normal',
            '',
            'VICTORY',
            'Good Resources: 0        Islamist Resources: 1',
            'Fair/Good Countries: 3   Poor/Islamist Countries: 4',
            '',
            'GWOT',
            'US Posture: Hard    World Posture: Hard 1',
            'US Prestige: 7',
            '',
            'TROOPS',
            'War: 9 troops available',
            '',
            'JIHADIST FUNDING',
            'Funding: 5    Cells Available: 11',
            '',
            'EVENTS',
            'Markers: None',
            'Lapsing: None',
            '',
            'US Reserves: 2'
        ])
コード例 #18
0
    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.country_names()).thenReturn(country_name)
        when(mock_randomizer).roll_d6(1).thenReturn([4])  # Value doesn't matter
        country = app.get_country(country_name)
        country.cadre = 1
        sleepers_before = country.sleeperCells

        # Invoke
        app.handle_radicalization(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")
コード例 #19
0
ファイル: test_is_adjacent.py プロジェクト: andrewswan/lwotai
 def test_is_adjacent(self):
     app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
     self.assertTrue(app.is_adjacent("Iran", "Iraq"))
     self.assertTrue(app.is_adjacent("Germany", "Spain"))
     self.assertTrue(app.is_adjacent("Libya", "Italy"))
     self.assertTrue(app.is_adjacent("Benelux", "Russia"))
     self.assertTrue(app.is_adjacent("Lebanon", "France"))
     self.assertFalse(app.is_adjacent("United States", "Lebanon"))
コード例 #20
0
    def _assert_adjust_posture(self,
                               user_input,
                               expected_posture,
                               expected_successful=True):
        # Set up
        app = Labyrinth(1,
                        1,
                        self.set_up_test_scenario,
                        test_user_input=[user_input])
        country = app.get_country(
            "France")  # Only non-muslim countries have a posture
        self.assertEqual(country.get_posture(), None)  # means "Untested"

        # Invoke
        successful = app.adjust_country_posture(country.name)

        # Check
        self.assertEqual(successful, expected_successful)
        self.assertEqual(country.get_posture(), expected_posture)
コード例 #21
0
def _create_game():
    """Factory function for a new game"""
    print ""
    scenario_number = Utils.choose_option("Choose Scenario", scenario_names())
    print ""
    ideology_number = choose_ideology()
    print ""
    ai_rolls = Utils.getUserYesNoResponse(
        "Do you want the program to roll dice for you?")
    return Labyrinth(scenario_number, ideology_number, ai_rolls=ai_rolls)
コード例 #22
0
ファイル: test_iran.py プロジェクト: andrewswan/lwotai
    def test_is_not_schengen(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = Iran(app)

        # Invoke
        schengen = iran.schengen

        # Check
        self.assertFalse(schengen)
コード例 #23
0
ファイル: test_iran.py プロジェクト: andrewswan/lwotai
    def test_is_fair(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = Iran(app)

        # Invoke
        result = iran.is_fair()

        # Check
        self.assertTrue(result)
コード例 #24
0
ファイル: test_iran.py プロジェクト: andrewswan/lwotai
    def test_is_not_good(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = Iran(app)

        # Invoke
        result = iran.is_good()

        # Check
        self.assertFalse(result)
コード例 #25
0
ファイル: test_iran.py プロジェクト: andrewswan/lwotai
    def test_cannot_be_made_hard(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = Iran(app)

        # Invoke
        try:
            iran.make_hard()
            self.fail("Should have raised an Exception")
        except Exception as e:
            # Check
            self.assertEqual("Not in Iran", e.message)
コード例 #26
0
ファイル: test_iran.py プロジェクト: andrewswan/lwotai
    def test_major_jihad_is_not_possible(self):
        # Set up
        app = Labyrinth(1, 1, self.set_up_blank_test_scenario)
        iran = Iran(app)
        iran.sleeperCells = 5
        iran.change_troops(-999)

        # Invoke
        major_jihad_possible = iran.is_major_jihad_possible(3, 5, False)

        # Check
        self.assertFalse(major_jihad_possible)
コード例 #27
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.set_posture("United States", HARD)
        for country in schengen_countries:
            country.remove_posture()

        # Invoke
        destinations = app.travel_destinations_schengen_visas()

        # Check
        self.assertEqual(destinations, chosen_countries)
コード例 #28
0
    def test_turn_file_can_be_saved_and_loaded(self):
        """Tests that the game can be saved to and loaded from a turn file"""
        # Set up
        saver = Saver()
        game_to_save = Labyrinth(1, 1)
        turn_number = 9999  # so as not to overwrite a real turn file
        game_to_save.turn = turn_number
        saver.save_current_turn_file(game_to_save)

        # Invoke
        loaded_game = saver.load_turn_file(turn_number)

        # Check
        self.assertEqual(loaded_game.backlashInPlay,
                         game_to_save.backlashInPlay)
        self.assertEqual(loaded_game.cells, game_to_save.cells)
        self.assertEqual(loaded_game.funding, game_to_save.funding)
        self.assertEqual(loaded_game.gameOver, game_to_save.gameOver)
        self.assertEqual(loaded_game.history, game_to_save.history)
        self.assertEqual(loaded_game.ideology, game_to_save.ideology)
        self.assertEqual(loaded_game.lapsing, game_to_save.lapsing)
        self.assertEqual(loaded_game.markers, game_to_save.markers)
        self.assertEqual(loaded_game.phase, game_to_save.phase)
        self.assertEqual(loaded_game.prestige, game_to_save.prestige)
        self.assertEqual(loaded_game.roll_turn, game_to_save.roll_turn)
        self.assertEqual(loaded_game.scenario, game_to_save.scenario)
        self.assertEqual(loaded_game.startYear, game_to_save.startYear)
        self.assertEqual(loaded_game.troops, game_to_save.troops)
        self.assertEqual(loaded_game.turn, game_to_save.turn)
        self.assertEqual(loaded_game.undo, game_to_save.undo)
        self.assertEqual(loaded_game.validCountryMarkers,
                         game_to_save.validCountryMarkers)
        self.assertEqual(loaded_game.validGlobalMarkers,
                         game_to_save.validGlobalMarkers)
        self.assertEqual(loaded_game.validLapsingMarkers,
                         game_to_save.validLapsingMarkers)
コード例 #29
0
    def test_adding_three_ops_only_sets_to_two(self):
        # Set up
        app = Labyrinth(1, 1, LabyrinthTestCase.set_up_blank_test_scenario)
        assert app.us_reserves == 0
        app.play_us_card(116)  # 3 ops

        # Invoke
        app.deploy_reserves()

        # Check
        self.assertEqual(2, app.us_reserves)
コード例 #30
0
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.country_distance(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)