def test_player_not_thrown_enough_is_fail(): number_of_chances = 1 required_value = 10 test_criteria = GreaterThanCriterion(number_of_chances, required_value) rolls = [1] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "False")
def test_player_thrown_enough__over_multiple_rolls_is_pass(): number_of_chances = 3 required_value = 4 test_criteria = GreaterThanCriterion(number_of_chances, required_value) rolls = [1, 2, 5] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "True")
def test_player_thrown_exact_is_pass(): number_of_chances = 1 required_value = 3 test_criteria = ExactMatchCriterion(number_of_chances, required_value) rolls = [3] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert(test_criteria.criteria_state() == "True")
def test_player_thrown_odd_is_pass_over_multiple_throws(): number_of_chances = 5 required_value = 3 is_odd = True test_criteria = OddEvenValueCriterion(number_of_chances, required_value, is_odd) rolls = [1, 4, 6, 5, 3] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "True")
def test_player_thrown_even_is_pass(): number_of_chances = 1 required_value = 1 is_odd = False test_criteria = OddEvenValueCriterion(number_of_chances, required_value, is_odd) rolls = [2] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "True")
def test_player_thrown_in_bounds_over_multiple_rolls_is_pass(): number_of_chances = 3 required_value = 4 boundary_offset = 1 test_criteria = BoundedMatchCriterion(number_of_chances, required_value, boundary_offset) rolls = [1, 2, 5] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "True")
def test_player_not_thrown_in_bounds_is_fail(): number_of_chances = 1 required_value = 4 boundary_offset = 1 test_criteria = BoundedMatchCriterion(number_of_chances, required_value, boundary_offset) rolls = [1] test_game_state = GameState() test_game_state.set_rolls(rolls) console_input = ConsoleInput() test_criteria.execute(test_game_state, console_input) assert (test_criteria.criteria_state() == "False")
def generate_game_state(number_of_rolls): player_items = get_player_items() player_rolls = get_player_rolls(number_of_rolls) game_state = GameState() game_state.set_items(player_items) game_state.set_rolls(player_rolls) return game_state logger = logging.getLogger('root') logger.setLevel(level="INFO") try: configuration = get_configuration() score = 0 console_input = ConsoleInput() for monster in configuration["monsters"]: game_monster = Monster(monster) game_state = generate_game_state(game_monster._required_rolls) if(game_monster.battle(game_state, console_input)): score = score + 1 logger.info("You defeated %s monsters", score) except Exception as exc: print("Should not fail " + str(exc)) tb = traceback.format_exc() print(tb)