def test_drawing_a_graph_with_sokoban(): main = level_chain(4, "main") sokoban = level_chain(2, "sokoban", 2) main[3].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(main[3], (2, 2)) dungeon = graph(main + sokoban) expect(dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: | | sokoban |", "| (nothing interesting) | |=========================|", "| | | Level 2: |", "| Level 2: | | (nothing interesting) |", "| (nothing interesting) | | |", "| | | Level 3: |", "| Level 3: | | (nothing interesting) |", "| (nothing interesting) | *| |", "| | / '-------------------------'", "| Level 4: |/", "| (nothing interesting) |", "| |", "' ... '", ])
def test_drawing_a_graph_with_both_mines_and_sokoban(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) sokoban = level_chain(2, "sokoban", 2) more_main[-1].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(more_main[-1], (2, 2)) dungeon = graph(levels + more_main + sokoban) expect(dungeon, [ " .-------------------------.", " | main |", " .-------------------------. |=========================| .-------------------------.", " | sokoban | | Level 1: |\ | mines |", " |=========================| | (nothing interesting) | \ |=========================|", " | Level 2: | | | *| Level 2: |", " | (nothing interesting) | | Level 2: | | (nothing interesting) |", " | | | (nothing interesting) | | |", " | Level 3: | | | | Level 3: |", " | (nothing interesting) |* | Level 3: | | (nothing interesting) |", " | | \ | (nothing interesting) | | |", " '-------------------------' \| | | Level 4: |", " | Level 4: | | (nothing interesting) |", " | (nothing interesting) | | |", " | | ' ... '", " ' ... '", ], 50, 0)
def test_drawing_a_graph_with_mines_that_have_a_branch_themselves(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") levels[2].change_branch_to("other") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) dungeon = graph(levels + more_main) expect(dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: |\ | mines |", "| (nothing interesting) | \ |=========================| .-------------------------.", "| | *| Level 2: |\ | other |", "| Level 2: | | (nothing interesting) | \ |=========================|", "| (nothing interesting) | | | *| Level 3: |", "| | ' ... ' | (nothing interesting) |", "| Level 3: | | |", "| (nothing interesting) | | Level 4: |", "| | | (nothing interesting) |", "| Level 4: | | |", "| (nothing interesting) | ' ... '", "| |", "' ... '", ])
def test_is_a_junction_when_there_are_two_children(): main = level_chain(2, "main") mines = level_chain(2, "mines", start_at=2) main[0].add_stairs(mines[0], (2, 2)) mines[0].add_stairs(main[0], (1, 1)) assert main[0].is_a_junction()
def test_drawing_a_graph_with_sokoban(): main = level_chain(4, "main") sokoban = level_chain(2, "sokoban", 2) main[3].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(main[3], (2, 2)) dungeon = graph(main + sokoban) expect( dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: | | sokoban |", "| (nothing interesting) | |=========================|", "| | | Level 2: |", "| Level 2: | | (nothing interesting) |", "| (nothing interesting) | | |", "| | | Level 3: |", "| Level 3: | | (nothing interesting) |", "| (nothing interesting) | *| |", "| | / '-------------------------'", "| Level 4: |/", "| (nothing interesting) |", "| |", "' ... '", ], )
def test_drawing_a_graph_with_mines_that_have_a_branch_themselves(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") levels[2].change_branch_to("other") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) dungeon = graph(levels + more_main) expect( dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: |\ | mines |", "| (nothing interesting) | \ |=========================| .-------------------------.", "| | *| Level 2: |\ | other |", "| Level 2: | | (nothing interesting) | \ |=========================|", "| (nothing interesting) | | | *| Level 3: |", "| | ' ... ' | (nothing interesting) |", "| Level 3: | | |", "| (nothing interesting) | | Level 4: |", "| | | (nothing interesting) |", "| Level 4: | | |", "| (nothing interesting) | ' ... '", "| |", "' ... '", ], )
def test_a_level_with_two_parents_is_a_junction(): main = level_chain(3, "main") sokoban = level_chain(2, "sokoban") main[2].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(main[2], (2, 2)) assert main[2].is_a_junction()
def test_complex_map_finds_start_of_sub_branch_when_initialized_with_middle_level(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) sokoban = level_chain(2, "sokoban", 2) more_main[-1].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(more_main[-1], (2, 2)) branch = Branch(levels[2]) assert branch.start == levels[1]
def test_level_chain_with_two_junctions_has_two_subbranches(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) sokoban = level_chain(2, "sokoban", 2) more_main[-1].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(more_main[-1], (2, 2)) branch = Branch(levels[0]) assert len(branch.sub_branches()) == 2
def test_complex_map_finds_start_of_sub_branch_when_initialized_with_middle_level( ): levels = level_chain(4, "main") levels[1].change_branch_to("mines") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) sokoban = level_chain(2, "sokoban", 2) more_main[-1].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(more_main[-1], (2, 2)) branch = Branch(levels[2]) assert branch.start == levels[1]
def test_level_with_branch_has_a_branch(): levels = level_chain(2, "main") levels[1].change_branch_to("mines") first = levels[0] assert first.has_a_branch() == True assert first.branches() == [levels[1]]
def test_changing_branches_changes_only_those_levels_that_are_below_the_branch_that_changed( ): levels = level_chain(5, "main") levels[1].change_branch_to("mines") assert all(l.branch == "mines" for l in levels if l.dlvl > 1) assert levels[0].branch == "main"
def test_drawing_a_dungeon_with_multiple_sub_branches_properly_computes_bounds(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") levels[2].change_branch_to("other") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) window = newpad() m = Minimap() dungeon = fixed_graph(levels + more_main) left, right, top, bottom = m.draw_dungeon(dungeon, window, 0, 0, get_color)[:-2] assert left == 0 assert right == 87 assert top == 0 assert bottom == 16
def test_changing_branch_to_sokoban_doesnt_change_children_branches(): levels = level_chain(5, "main") sokoban = Level(3) levels[4].add_stairs(sokoban, (3, 3)) sokoban.add_stairs(levels[4], (4, 4)) sokoban.change_branch_to("sokoban") assert sokoban.branch == "sokoban" assert levels[4].branch == "main"
def test_a_current_level_in_a_single_branch_is_properly_bounded(): levels = level_chain(3, "main") window = newpad() m = Minimap() dungeon = fixed_graph(levels) x, y = m.draw_dungeon(dungeon, window, 0, 0, get_color)[-2:] assert x == 0 assert y == 3
def test_drawing_a_dungeon_with_multiple_sub_branches_properly_computes_bounds( ): levels = level_chain(4, "main") levels[1].change_branch_to("mines") levels[2].change_branch_to("other") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) window = newpad() m = Minimap() dungeon = fixed_graph(levels + more_main) left, right, top, bottom = m.draw_dungeon(dungeon, window, 0, 0, get_color)[:-2] assert left == 0 assert right == 87 assert top == 0 assert bottom == 16
def test_drawing_a_dungeon_with_one_branch_offset_properly_computes_bounds(): levels = level_chain(3, "main") window = newpad() m = Minimap() dungeon = fixed_graph(levels) left, right, top, bottom = m.draw_dungeon(dungeon, window, 10, 10, get_color)[:-2] assert left == 10 assert right == 37 assert top == 10 assert bottom == 23
def test_a_current_level_on_a_second_branch_is_properly_bounded(): levels = level_chain(3, "main") levels[1].change_branch_to("mines") window = newpad() m = Minimap() dungeon = fixed_graph(levels) dungeon.current = levels[1] x, y = m.draw_dungeon(dungeon, window, 0, 0, get_color)[-2:] assert x == 30 assert y == 5
def test_drawing_a_graph_with_multiple_branches_colors_a_current_level_on_the_main_branch(): levels = level_chain(3, "main") levels[1].change_branch_to("mines") window = newpad() window.should_receive("chgat").with_args(3, 1, 25, curses.A_BOLD | 0).times(1) window.should_receive("chgat").with_args(4, 1, 25, curses.A_BOLD | 0).times(1) window.should_receive("chgat").with_args(5, 1, 25, curses.A_BOLD | 0).times(1) m = Minimap() dungeon = fixed_graph(levels) m.draw_dungeon(dungeon, window, 0, 0, get_color)
def test_drawing_a_dungeon_with_one_branch_properly_computes_bounds(): levels = level_chain(3, "main") window = newpad() m = Minimap() dungeon = fixed_graph(levels) left, right, top, bottom = m.draw_dungeon(dungeon, window, 0, 0, get_color)[:-2] assert left == 0 assert right == 27 assert top == 0 assert bottom == 13
def test_drawing_a_dungeon_with_multiple_branches_properly_computes_bounds(): levels = level_chain(3, "main") levels[1].change_branch_to("mines") window = newpad() m = Minimap() dungeon = fixed_graph(levels) left, right, top, bottom = m.draw_dungeon(dungeon, window, 0, 0, get_color)[:-2] assert left == 0 assert right == 57 assert top == 0 assert bottom == 12
def test_drawing_a_graph_with_both_mines_and_sokoban(): levels = level_chain(4, "main") levels[1].change_branch_to("mines") more_main = level_chain(3, "main", 2) more_main[0].add_stairs(levels[0], (5, 5)) levels[0].add_stairs(more_main[0], (5, 5)) sokoban = level_chain(2, "sokoban", 2) more_main[-1].add_stairs(sokoban[-1], (1, 1)) sokoban[-1].add_stairs(more_main[-1], (2, 2)) dungeon = graph(levels + more_main + sokoban) expect( dungeon, [ " .-------------------------.", " | main |", " .-------------------------. |=========================| .-------------------------.", " | sokoban | | Level 1: |\ | mines |", " |=========================| | (nothing interesting) | \ |=========================|", " | Level 2: | | | *| Level 2: |", " | (nothing interesting) | | Level 2: | | (nothing interesting) |", " | | | (nothing interesting) | | |", " | Level 3: | | | | Level 3: |", " | (nothing interesting) |* | Level 3: | | (nothing interesting) |", " | | \ | (nothing interesting) | | |", " '-------------------------' \| | | Level 4: |", " | Level 4: | | (nothing interesting) |", " | (nothing interesting) | | |", " | | ' ... '", " ' ... '", ], 50, 0, )
def test_drawing_a_graph_with_multiple_branches_colors_a_current_level_on_the_main_branch( ): levels = level_chain(3, "main") levels[1].change_branch_to("mines") window = newpad() window.should_receive("chgat").with_args(3, 1, 25, curses.A_BOLD | 0).times(1) window.should_receive("chgat").with_args(4, 1, 25, curses.A_BOLD | 0).times(1) window.should_receive("chgat").with_args(5, 1, 25, curses.A_BOLD | 0).times(1) m = Minimap() dungeon = fixed_graph(levels) m.draw_dungeon(dungeon, window, 0, 0, get_color)
def test_moving_down_main_then_up_one_and_down_to_the_mines_before_mines_are_identified(): levels = level_chain(3, "main") m = Map(levels[-1], 3, 2) m.levels = set(levels) m.travel_by_stairs(2, (2, 3)) assert len(m.levels) == 3 m.move(4, 4) m.travel_by_stairs(3, (4, 4)) assert len(m.levels) == 4 m.change_branch_to("mines") assert len([l for l in m.levels if l.branch == "main"]) == 3 assert len([l for l in m.levels if l.branch == "mines"]) == 1
def test_moving_down_main_then_up_one_and_down_to_the_mines_before_mines_are_identified( ): levels = level_chain(3, "main") m = Map(levels[-1], 3, 2) m.levels = set(levels) m.travel_by_stairs(2, (2, 3)) assert len(m.levels) == 3 m.move(4, 4) m.travel_by_stairs(3, (4, 4)) assert len(m.levels) == 4 m.change_branch_to("mines") assert len([l for l in m.levels if l.branch == "main"]) == 3 assert len([l for l in m.levels if l.branch == "mines"]) == 1
def test_drawing_a_graph_with_mines(): levels = level_chain(3, "main") levels[1].change_branch_to("mines") dungeon = graph(levels) expect(dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: |\ | mines |", "| (nothing interesting) | \ |=========================|", "| | *| Level 2: |", "' ... ' | (nothing interesting) |", " | |", " | Level 3: |", " | (nothing interesting) |", " | |", " ' ... '", ])
def test_drawing_a_graph_with_mines(): levels = level_chain(3, "main") levels[1].change_branch_to("mines") dungeon = graph(levels) expect( dungeon, [ ".-------------------------.", "| main |", "|=========================| .-------------------------.", "| Level 1: |\ | mines |", "| (nothing interesting) | \ |=========================|", "| | *| Level 2: |", "' ... ' | (nothing interesting) |", " | |", " | Level 3: |", " | (nothing interesting) |", " | |", " ' ... '", ], )
def graph(levels=None): if levels is None: levels = level_chain(5, "main") dmap = Map(levels[0], 0, 0) dmap.levels = set(levels) return dmap
def test_changing_branches_changes_my_childrens_branch(): levels = level_chain(3, "main") levels[0].change_branch_to("mines") assert all(l.branch == "mines" for l in levels)
def test_is_not_a_junction_when_there_is_only_one_child(): main = level_chain(2, "main") assert not main[0].is_a_junction()
def test_a_level_with_a_parent_and_a_child_is_not_a_junction(): main = level_chain(3, "main") assert not main[1].is_a_junction()
def fixed_graph(levels=None): if levels is None: levels = level_chain(5, "main") dmap = Map(levels[0], 0, 0) dmap.levels = set(levels) return dmap
def test_level_chain_with_one_junction_should_have_one_subbranch(): levels = level_chain(5, "main") levels[1].change_branch_to("mines") assert levels[0].has_a_branch() == True branch = Branch(levels[0]) assert len(branch.sub_branches()) == 1
def test_single_level_chain_finds_start_when_initialized_with_middle_level(): levels = level_chain(5, "main") branch = Branch(levels[3]) assert branch.start == levels[0]
def test_level_with_only_one_child_that_doesnt_have_a_branch_has_no_branch(): levels = level_chain(2, "main") first = levels[0] assert first.has_a_branch() == False
def test_single_level_chain_has_no_branches(): levels = level_chain(5, "main") branch = Branch(levels[0]) assert branch.sub_branches() == []
def test_changing_branches_changes_only_those_levels_that_are_below_the_branch_that_changed(): levels = level_chain(5, "main") levels[1].change_branch_to("mines") assert all(l.branch == "mines" for l in levels if l.dlvl > 1) assert levels[0].branch == "main"