diff options
author | Marianne Chevrot <blackmoor+git@devys.org> | 2020-05-17 11:09:15 +0200 |
---|---|---|
committer | Marianne Chevrot <blackmoor+git@devys.org> | 2020-05-17 11:09:15 +0200 |
commit | e019b29657a69c19121c6a145d065b7e23baf093 (patch) | |
tree | d386dba3abfc8b1873761d3f055d1d206279d5c6 | |
parent | 2b5375319230b4c317846da3b70e4660a06731f2 (diff) | |
download | kana_quest_solver-e019b29657a69c19121c6a145d065b7e23baf093.tar.gz kana_quest_solver-e019b29657a69c19121c6a145d065b7e23baf093.tar.bz2 kana_quest_solver-e019b29657a69c19121c6a145d065b7e23baf093.zip |
add a test to grid generator
-rwxr-xr-x | solver.py | 27 | ||||
-rw-r--r-- | tests_solver/test_solver.py | 33 |
2 files changed, 48 insertions, 12 deletions
@@ -354,6 +354,20 @@ def print_score_over(node, target_score): print_score_over(child, target_score) +def search_all_solution(args, kanagrid, target_score, max_actions): + grids = {} + generate_all_possible_grids(kanagrid, grids=grids, max_actions=max_actions) + for grid in grids.values(): + grid.update_score() + if grid.score >= target_score and grid.myst_count == 0: + print("="*80) + if args['-p']: + print(repr_grid_with_parents(grid)) + else: + print(grid) + return grid + + def main(): args = docopt.docopt(__doc__) @@ -371,18 +385,7 @@ def main(): if args['--print']: return - del input_dict - - grids = {} - generate_all_possible_grids(kanagrid, grids=grids, max_actions=max_actions) - for grid in grids.values(): - grid.update_score() - if grid.score >= target_score and grid.myst_count == 0: - print("="*80) - if args['-p']: - print(repr_grid_with_parents(grid)) - else: - print(grid) + search_all_solution(args, kanagrid, target_score, max_actions) if __name__ == '__main__': diff --git a/tests_solver/test_solver.py b/tests_solver/test_solver.py index 1f178cc..1d441ff 100644 --- a/tests_solver/test_solver.py +++ b/tests_solver/test_solver.py @@ -195,3 +195,36 @@ def test_kana_arrow_swap(): else: assert kanagrid_test is None + +def test_solver_load_and_type_1(): + # ./solver.py tests_solver/level_test_type.yaml + + kanagrid_orig = KanaGrid((6, 2), [ + Kana("ar_r", "sa"), Kana("norm" ), Kana("norm", "so"), Kana("rock", "se"), Kana("myst", "ka"), Kana("ar_d", "na"), + Kana("ar_u", "su"), Kana("ar_l", "nu"), Kana("void" ), Kana("void" ), Kana("froz" ), Kana("froz", "ke"), + ]) + + expected_grid = KanaGrid((6, 2), [ + Kana("ar_u", "su"), Kana("ar_r", "sa"), Kana("norm", "so"), Kana("rock", "se"), Kana("froz", "ke"), Kana("norm", "ka"), + Kana("ar_l", "nu"), Kana("norm" ), Kana("void" ), Kana("void" ), Kana("froz" ), Kana("ar_d", "na"), + ], action_count=6, score=8) + + type_yaml_level_file = 'tests_solver/level_test_type.yaml' + with open(type_yaml_level_file, encoding='utf8') as stream: + input_dict = yaml.safe_load(stream) + loaded_grid = KanaGrid.load(input_dict) + target_score = input_dict['target_score'] + max_actions = input_dict['max_actions'] + + mock_args = {'--help': False, + '--print': False, + '-p': False, + 'YAML_GRID': type_yaml_level_file, + } + + assert loaded_grid == kanagrid_orig + + kanagrid_new = search_all_solution(mock_args, loaded_grid, target_score, max_actions) + + assert kanagrid_new == expected_grid + |