Beispiel #1
0
def test_blocksworld_add_and_remove():
    lang = blocksworld.generate_small_fstrips_bw_language()
    model = Model(lang)

    clear = lang.get_predicate('clear')
    b1 = lang.get_constant('b1')

    model.add(clear, b1)
    model.remove(clear, b1)
    assert evaluate(clear(b1), model) is False
Beispiel #2
0
def test_predicate_extensions():
    lang = tarski.language()
    pred = lang.predicate('pred', lang.Object, lang.Object)

    o1 = lang.constant("o1", lang.Object)
    o2 = lang.constant("o2", lang.Object)

    model = Model(lang)

    with pytest.raises(errors.ArityMismatch):
        # This should raise an error, as the predicate is binary
        model.add(pred)

    with pytest.raises(ValueError):
        # This should raise an error, as the predicate sort does not coincide with the sort of the parameters
        model.add(pred, 1, 2)

    model.add(pred, o1, o2)
    assert not model.holds(pred, (o2, o1))  # Make sure the order in which the elements were added is respected!
    assert model.holds(pred, (o1, o2))

    with pytest.raises(KeyError):
        # This should raise an error, as the tuple does not belong to the predicate's extension
        model.remove(pred, o2, o1)

    model.remove(pred, o1, o2)
    with pytest.raises(KeyError):
        # This should raise an error, as the tuple has been removed
        model.remove(pred, o1, o2)