Пример #1
0
def test_insertBlockBetween_100perecent(render=False):
    # Prep
    root = Root("Start")
    goal = Goal("Finish")

    a = root.action("A")
    b = a.action("B")
    c = b.action("C")

    c.connectTo(goal)

    #Before
    assert (len(b.edges) == 1)

    # Create a  second block with a pSuccess of 100
    block = Block(label="Test Block", implemented=True, cost=5000, pDefend=100)

    # The tested function
    block.insertBetween(b, c)

    # After
    assert (
        len(b.edges) == 1
    )  # As the block has 100% chance of working, c should be unreachable
    assert (b.edges[0].childNode == block)

    if render:
        Renderer().render(root=root,
                          fname=inspect.currentframe().f_code.co_name)
Пример #2
0
def test_insertBetween_50perecent(render=False):
    # Prep
    root = Root("Start")
    goal = Goal("Finish")

    a = root.action("A")
    b = a.action("B")
    c = b.action("C")

    c.connectTo(goal)

    # Verify prep
    assert (len(a.edges) == 1)
    assert (a.edges[0].childNode == b)

    # Create a block
    block = Block(label="Test Block", implemented=True, cost=5000, pDefend=50)

    # The tested function
    block.insertBetween(a, b)

    # After
    assert (len(a.edges) == 1)
    assert (len(block.edges) == 1)
    assert (a.edges[0].childNode.edges[0].childNode == b)

    if render:
        Renderer().render(root=root,
                          fname=inspect.currentframe().f_code.co_name)
Пример #3
0
def test_repr():
    root = Root("root")
    goal = Goal("goal")

    throws = root.action("A")
    dodge = throws.block("B", implemented=True)

    description = throws.edges[0].__repr__()

    assert description == "Edge 'Fail' connects 'A' to 'B'"
Пример #4
0
def test_detectShortcut():
    root = Root("have rock")
    goal = Goal("hit player")

    throws = root.action("throw rock")
    alarm = throws.detect("player sees rock", implemented=True)

    assert isinstance(alarm, Detect)
    assert len(throws.edges) == 1
    edge = throws.edges[0]

    assert isinstance(edge, Edge)
    assert edge.parentNode == throws
    assert edge.childNode == alarm
Пример #5
0
def test_blockShortcut():
    root = Root("have rock")
    goal = Goal("hit player")

    throws = root.action("throw rock")
    dodge = throws.block("dodge", implemented=True)

    assert len(throws.edges) == 1
    assert isinstance(throws.edges[0], Edge)
    edge = throws.edges[0]

    assert edge.childNode == dodge
    assert edge.parentNode == throws

    assert isinstance(dodge, Block)
    assert isinstance(dodge, Node)
    assert len(dodge.parentEdges) == 1
    assert isinstance(dodge.parentEdges[0], Edge)