Ejemplo n.º 1
0
def test_test_constraint():
    animals = ["dog", "cat"]
    w1 = World(animals)
    c1 = ("dog", "left of", "cat")
    c2 = ("cat", "right of", "dog")
    c3 = ("dog", "in front of", "cat")
    c4 = ("cat", "in back of", "dog")
    w1.set_position("dog", 1, 1)
    w1.set_position("cat", 2, 2)
    assert w1.test_constraint(c1)
    assert w1.test_constraint(c2)
    assert w1.test_constraint(c3)
    assert w1.test_constraint(c4)
Ejemplo n.º 2
0
def test_set_position():
    w1 = World()
    w1.set_position("dog", 1, 1)
    assert w1.animals["dog"].x == 1
    assert w1.animals["dog"].y == 1
    try:
        w1.set_position("dog", 0, 0)
    except Exception as e:
        assert type(e) is ValueError

    w2 = World(["dog"])
    w2.set_position("dog", 1, 1)
    assert w2.animals["dog"].x == 1
    assert w2.animals["dog"].y == 1
    w2.set_position("cat", 0, 0)
    assert w2.animals["cat"].x == 0
    assert w2.animals["cat"].y == 0
Ejemplo n.º 3
0
def test_copy():
    w1 = World(["dog"])
    w1.set_position("dog", 1, 1)
    w2 = w1.copy()
    assert w1 is not w2  # not the same object
    assert str(w1) == str(w2)  # but identical contents