-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_grounding.py
31 lines (26 loc) · 1.02 KB
/
test_grounding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Testing of the decoupled grounding/solving API"""
import pytest
from clyngor import grounded_program, solve_from_grounded, solve as solve_standard, opt_models_from_clyngor_answers
from .definitions import run_with_clingo_binary_only
@run_with_clingo_binary_only
def test_simple():
prg = '1{p(a;b;c)}1.'
grounded = grounded_program(inline=prg)
found = frozenset(solve_from_grounded(grounded)) # clingo module cannot be used here
expected = frozenset(solve_standard(inline=prg))
assert found == expected
@run_with_clingo_binary_only
def test_with_opts():
ASP = r"""
q(1..10).
1{p(X): q(X)}3.
nb(odd,N):- N={p(X): X\2=0}.
nb(even,N):- N={p(X): X\2=1}.
nb(sum,N):- N=#sum{X:p(X)}.
#minimize{N,2:nb(odd,N)}.
#maximize{N,1:nb(even,N)}.
"""
grounded = grounded_program(inline=ASP)
found = frozenset(opt_models_from_clyngor_answers(solve_from_grounded(grounded).by_predicate))
expected = frozenset(opt_models_from_clyngor_answers(solve_standard(inline=ASP).by_predicate))
assert found == expected