diff options
author | Marianne Chevrot <blackmoor+git@devys.org> | 2020-05-05 20:49:29 +0200 |
---|---|---|
committer | Marianne Chevrot <blackmoor+git@devys.org> | 2020-05-05 20:56:47 +0200 |
commit | 4e9ad30ac8a1bc35ed2c2548793d70579e30732e (patch) | |
tree | 23caed3a1c429715aa3103d720063f3745407a8a /tests_solver | |
parent | 7a077a93c8ca55776302042fd9e526e7c09559ef (diff) | |
download | kana_quest_solver-4e9ad30ac8a1bc35ed2c2548793d70579e30732e.tar.gz kana_quest_solver-4e9ad30ac8a1bc35ed2c2548793d70579e30732e.tar.bz2 kana_quest_solver-4e9ad30ac8a1bc35ed2c2548793d70579e30732e.zip |
Add arrows kana type and improved grid repr
Diffstat (limited to 'tests_solver')
-rw-r--r-- | tests_solver/level_test_ar_x.yaml | 8 | ||||
-rw-r--r-- | tests_solver/level_test_type.yaml | 9 | ||||
-rw-r--r-- | tests_solver/level_test_type_short.yaml | 9 | ||||
-rw-r--r-- | tests_solver/test_solver.py | 141 |
4 files changed, 160 insertions, 7 deletions
diff --git a/tests_solver/level_test_ar_x.yaml b/tests_solver/level_test_ar_x.yaml new file mode 100644 index 0000000..633a843 --- /dev/null +++ b/tests_solver/level_test_ar_x.yaml @@ -0,0 +1,8 @@ +# kana quest grid level 1.1 +size: [3, 1] +max_actions: 1 +target_score: 2 +grid: [ + [ar_r, su ], [empt, null], [norm, so ], +] +# The kana 'no' need to be protected else the program convert it into False... diff --git a/tests_solver/level_test_type.yaml b/tests_solver/level_test_type.yaml new file mode 100644 index 0000000..0eec70a --- /dev/null +++ b/tests_solver/level_test_type.yaml @@ -0,0 +1,9 @@ +# kana quest grid level 1.1 +size: [6, 2] +max_actions: 6 +target_score: 8 +grid: [ + [ar_r, sa ], [empt, null], [norm, so ], [rock, se ], [myst, ka ], [ar_d, na ], + [ar_u, su ], [ar_l, nu ], [void, null], [void, null], [void, null], [froz, ke ], +] +# The kana 'no' need to be protected else the program convert it into False... diff --git a/tests_solver/level_test_type_short.yaml b/tests_solver/level_test_type_short.yaml new file mode 100644 index 0000000..7fa3a9a --- /dev/null +++ b/tests_solver/level_test_type_short.yaml @@ -0,0 +1,9 @@ +# kana quest grid level 1.1 +size: [2, 2] +max_actions: 3 +target_score: 3 +grid: [ + [myst, ka ], [ar_d, ne ], + [void, null], [froz, ke ], +] +# The kana 'no' need to be protected else the program convert it into False... diff --git a/tests_solver/test_solver.py b/tests_solver/test_solver.py index e2b45a5..82aca73 100644 --- a/tests_solver/test_solver.py +++ b/tests_solver/test_solver.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os +import pprint import sys sys.path.append(os.getcwd()) @@ -8,13 +9,29 @@ sys.path.append(os.getcwd()) from solver import * def test_is_swappable(): - assert is_swappable(Kana("norm", "su"), Kana("norm", "su")) - assert is_swappable(Kana("froz", "su"), Kana("norm", "su")) - assert is_swappable(Kana("norm", "su"), Kana("empt")) - assert is_swappable(Kana("empt"), Kana("froz", "su")) - assert not is_swappable(Kana("norm", "su"), Kana("rock", "su")) - assert not is_swappable(Kana("froz", "su"), Kana("froz", "su")) - assert not is_swappable(Kana("empt"), Kana("empt")) + + swappable_grids = [ + [Kana("norm", "su"), Kana("norm", "su")], + [Kana("froz", "su"), Kana("norm", "su")], + [Kana("norm", "su"), Kana("empt" )], + [Kana("empt" ), Kana("froz", "su")], + ] + + for swappable_grid in swappable_grids: + kanagrid = KanaGrid((2, 1), swappable_grid) + print(kanagrid.grid) + assert kanagrid.is_swappable((0, 0), (1, 0)) + + not_swappable_grids = [ + [Kana("norm", "su"), Kana("rock", "su")], + [Kana("froz", "su"), Kana("froz", "su")], + [Kana("empt" ), Kana("empt" )], + ] + + for not_swappable_grid in not_swappable_grids: + kanagrid = KanaGrid((2, 1), not_swappable_grid) + print(kanagrid.grid) + assert not kanagrid.is_swappable((0, 0), (1, 0)) def test_kana_grid(): @@ -47,3 +64,113 @@ def test_kana_grid(): assert kanagrid_new.grid == expected_grid + +def test_kana_arrow_swap(): + kanagrid_orig = KanaGrid((2, 1), [Kana("ar_r", "su"), Kana("empt",)]) + kanagrid_new = kanagrid_orig.action(pos=(0, 0), action_type="right") + expected_grid = KanaGrid((2, 1), [Kana("empt",), Kana("ar_r", "su")]) + + print("kanagrid_orig") + print(kanagrid_orig) + print("kanagrid_new") + print(kanagrid_new) + print("expected_grid") + print(expected_grid) + + assert kanagrid_new.grid == expected_grid.grid + +def test_kana_arrow_swap(): + moves = [ + { + 'move_ok': 'up', + 'other_move_ok': 'down', + 'dest_pos': (1, 0), + 'orig': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("ar_u", "ko"), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ]), + 'moved': KanaGrid((3, 3), [ + Kana("empt" ), Kana("ar_u", "ko"), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ], action_count=1), + }, + { + 'move_ok': 'right', + 'other_move_ok': 'left', + 'dest_pos': (2, 1), + 'orig': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("ar_r", "ko"), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ]), + 'moved': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("ar_r", "ko"), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ], action_count=1), + }, + { + 'move_ok': 'down', + 'other_move_ok': 'up', + 'dest_pos': (1, 2), + 'orig': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("ar_d", "ko"), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ]), + 'moved': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("ar_d", "ko"), Kana("empt" ), + ], action_count=1), + }, + { + 'move_ok': 'left', + 'other_move_ok': 'right', + 'dest_pos': (0, 1), + 'orig': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("ar_l", "ko"), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ]), + 'moved': KanaGrid((3, 3), [ + Kana("empt" ), Kana("empt" ), Kana("empt" ), + Kana("ar_l", "ko"), Kana("empt" ), Kana("empt" ), + Kana("empt" ), Kana("empt" ), Kana("empt" ), + ], action_count=1), + }, + ] + + for move in moves: + print("pprint.pprint(move):") + pprint.pprint(move) + for action in ("up", "right", "down", "left"): + print("\n"*3) + print("action:", action) + + # try to move arrowed kana + kanagrid_test = move['orig'].copy() + kanagrid_test = kanagrid_test.action((1, 1), action) + print("=== move arrowed kana ===") + print(kanagrid_test) + if action == move['move_ok']: + assert move['orig'].is_swappable((1, 1), move['dest_pos']) + assert kanagrid_test == move['moved'] + else: + assert kanagrid_test is None + + for other_pos in ((1, 0), (2, 1), (1, 2), (0, 1)): + # try to move other kana with the arrowed one + kanagrid_test = move['orig'].copy() + kanagrid_test = kanagrid_test.action(other_pos, action) + print("=== move other kana ===") + print(kanagrid_test) + if action == move['other_move_ok'] \ + and other_pos == move['dest_pos']: + assert move['orig'].is_swappable(other_pos, (1, 1)) + assert kanagrid_test == move['moved'] + else: + assert kanagrid_test is None + |