Exemplo n.º 1
0
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"
Exemplo n.º 2
0
def test_drawing_a_branch_with_multiple_levels_that_arent_monotonically_increasing_puts_an_ellipses_between_disjoins(
):
    levels = [Level(1), Level(5)]
    expect(levels, [
        ".-------------------------.", "| Dungeons of Doom        |",
        "|=========================|", "| Level 1:                |",
        "|   (nothing interesting) |", "|                         |",
        "| ...                     |", "|                         |",
        "| Level 5:                |", "|   (nothing interesting) |",
        "|                         |", "' ...                     '"
    ])
Exemplo n.º 3
0
def test_drawing_a_branch_with_multiple_levels_draws_all_the_levels():
    levels = [Level(1), Level(2), Level(3)]
    expect(levels, [
        ".-------------------------.", "| Dungeons of Doom        |",
        "|=========================|", "| Level 1:                |",
        "|   (nothing interesting) |", "|                         |",
        "| Level 2:                |", "|   (nothing interesting) |",
        "|                         |", "| Level 3:                |",
        "|   (nothing interesting) |", "|                         |",
        "' ...                     '"
    ])
Exemplo n.º 4
0
def test_teleporting_to_an_undiscovered_level_doesnt_link():
    m = Map(level(1), 1, 1)

    first = flexmock(Level(1))
    m.current = first

    first.should_receive("add_stairs").never
    flexmock(Level).new_instances(flexmock(Level(5))).once

    m.travel_by_teleport(5, (5, 5))

    assert m.current.dlvl == 5
    assert len(m.levels) == 2
Exemplo n.º 5
0
def test_traveling_down_an_existing_link_doesnt_create_a_new_link_or_level():
    m = Map(level(1), 1, 1)

    second = Level(2)

    first = flexmock(Level(1))
    first.should_receive("has_stairs_at").and_return(True).once
    first.should_receive("stairs_at").and_return(second)
    first.should_receive("add_stairs").never

    m.current = first

    m.travel_by_stairs(2, (2, 2))

    assert m.current == second
Exemplo n.º 6
0
def test_traveling_down_when_a_link_doesnt_exist_creates_a_new_link_and_level(
):
    m = Map(level(1), 1, 1)

    first = flexmock(Level(1))
    first.should_receive("has_stairs_at").and_return(False).once
    first.should_receive("add_stairs").with_args(object, (1, 1))

    m.current = first

    flexmock(Level).new_instances(flexmock(Level(5))).once

    m.travel_by_stairs(2, (2, 2))

    assert len(m.levels) == 2
Exemplo n.º 7
0
def test_moving_upstairs_from_to_a_known_level_that_isnt_yet_linked_with_the_current(
):
    m = Map(level(1), 2, 2)

    first = flexmock(Level(1))
    second = flexmock(Level(2))

    m.levels = set([first, second])
    m.current = second

    first.should_receive("add_stairs").with_args(second, (1, 1)).once
    second.should_receive("add_stairs").with_args(first, (2, 2)).once

    m.travel_by_stairs(1, (1, 1))

    assert m.current.dlvl == 1
Exemplo n.º 8
0
def test_switching_a_branch_changes_the_current_level_to_a_new_branch():
    m = Map(level(1), 2, 2)

    second = flexmock(Level(2))
    second.should_receive("change_branch_to").with_args("mines").once
    m.levels.add(second)
    m.current = second
    m.change_branch_to("mines")
Exemplo n.º 9
0
def test_drawing_a_branch_draws_the_header_and_the_border():
    level = Level(1)
    expect([level], [
        ".-------------------------.", "| Dungeons of Doom        |",
        "|=========================|", "| Level 1:                |",
        "|   (nothing interesting) |", "|                         |",
        "' ...                     '"
    ])
Exemplo n.º 10
0
def level_chain(size, branch, start_at=1):
    def link(first, second):
        first.add_stairs(second, (first.dlvl, second.dlvl))
        second.add_stairs(first, (second.dlvl, first.dlvl))
        return second

    levels = [Level(i, branch) for i in xrange(start_at, size + start_at)]
    reduce(link, levels)
    return levels
Exemplo n.º 11
0
def test_drawing_a_single_shop_indents_and_translates():
    level = Level(1)
    level.shops.add("random")

    expect(level, [
        "Level 1:",
        "  Shops:",
        "    * Random",
    ])
Exemplo n.º 12
0
def test_drawing_features_and_shops_draws_the_shops_first():
    level = Level(1)
    level.features.update(["Fountain", "Oracle"])
    level.shops.add("90/10 arm/weap")

    expect(level, [
        "Level 1:", "  Shops:", "    * 90/10 arm/weap", "  * Fountain",
        "  * Oracle"
    ])
Exemplo n.º 13
0
def test_drawing_a_single_level_draws_all_the_features():
    level = Level(1)
    level.features.add("Altar (neutral)")
    level.features.add("Altar (chaotic)")
    expect(level, [
        "Level 1:",
        "  * Altar (chaotic)",
        "  * Altar (neutral)",
    ])
Exemplo n.º 14
0
def test_walking_down_a_single_level_in_the_same_branch_that_doesnt_exists():
    m = Map(level(1), 1, 1)

    second = flexmock(Level(2))
    flexmock(Level).new_instances(second).once

    m.current.should_receive("add_stairs").with_args(second, (1, 1)).once
    second.should_receive("add_stairs").with_args(m.current, (2, 2)).once

    m.travel_by_stairs(2, (2, 2))

    assert m.current == second
Exemplo n.º 15
0
def test_drawing_features_sorts_them_first():
    from random import shuffle, seed
    seed(3141)

    level = Level(1)
    features = [str(i) for i in xrange(1, 10)]
    shuffle(features)
    assert features[0] != 1
    level.features.update(features)

    expected = ["Level 1:"] + ["  * %s" % i for i in xrange(1, 10)]
    expect(level, expected)
Exemplo n.º 16
0
def test_moving_up_stairs_to_an_unknown_level_creates_a_new_link_and_level():
    m = Map(level(1), 5, 5)

    fifth = flexmock(Level(5))
    fifth.should_receive("has_stairs_at").and_return(False).once
    fifth.should_receive("add_stairs").with_args(object, (5, 5))

    m.current = fifth

    m.travel_by_stairs(4, (4, 4))

    assert m.current.dlvl == 4
    assert len(m.levels) == 2
Exemplo n.º 17
0
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"
Exemplo n.º 18
0
def test_walking_up_a_single_level_in_the_same_branch_that_already_exists():
    first = level(1)
    m = Map(first, 1, 1)

    second = flexmock(Level(2))
    second.should_receive("add_stairs").once
    first.should_receive("add_stairs").once
    flexmock(Level).new_instances(second).once

    # Travel down once to create the second level
    m.travel_by_stairs(2, (2, 2))

    second.should_receive("has_stairs_at").and_return(True).once
    second.should_receive("stairs_at").and_return(first).once

    # Now traveling back up should go back to the first
    m.travel_by_stairs(1, (1, 1))

    assert len(m.levels) == 2
    assert m.current == first
Exemplo n.º 19
0
 def __init__(self, events):
     self.graph = Map(Level(1), 0, 0)
     self.level = 1
     self.went_through_lvl_tel = False
     self.events = events
Exemplo n.º 20
0
def test_a_branch_with_only_a_single_level_can_reference_that_level_at_the_right_index(
):
    levels = [Level(1)]
    expect_dlvl_at_index(1, 3, levels)
Exemplo n.º 21
0
def test_a_branch_with_disconnected_levels_has_the_furthest_at_the_right_index(
):
    levels = [Level(1), Level(5)]
    expect_dlvl_at_index(5, 8, levels)
Exemplo n.º 22
0
def level(dlvl):
    return flexmock(Level(dlvl))
Exemplo n.º 23
0
def test_a_branch_with_multiple_adjacent_levels_has_the_furthest_at_the_right_index(
):
    levels = [Level(1), Level(2), Level(3)]
    expect_dlvl_at_index(3, 9, levels)
Exemplo n.º 24
0
def test_level_with_no_children_doesnt_have_a_branch():
    l = Level(1, "main")

    assert l.has_a_branch() == False
Exemplo n.º 25
0
def test_changing_branches_changes_my_branch():
    l = Level(1, "main")
    l.change_branch_to("mines")
    assert l.branch == "mines"
Exemplo n.º 26
0
def test_changing_branches_changes_my_branch():
    l = Level(1, "main")
    l.change_branch_to("mines")
    assert l.branch == "mines"
Exemplo n.º 27
0
def test_drawing_a_single_levels_buffer_with_an_empty_level_writes_nothing_interesting(
):
    level = Level(1)
    assert len(level.features) == 0
    expect(level, ["Level 1:", "  (nothing interesting)"])
Exemplo n.º 28
0
def test_drawing_a_single_level_draws_the_correct_dlvl():
    level = Level(5)
    expect(level, ["Level 5:", "  (nothing interesting)"])
Exemplo n.º 29
0
def test_level_with_no_children_doesnt_have_a_branch():
    l = Level(1, "main")

    assert l.has_a_branch() == False