Skip to content

Commit

Permalink
added basic structure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Rühling committed Apr 15, 2024
1 parent 9a113ed commit bfefab2
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 24 deletions.
16 changes: 0 additions & 16 deletions examples/tests/test_cases.coom

This file was deleted.

6 changes: 3 additions & 3 deletions src/coomsolver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _parse_profile(self, profile: str) -> List[str]:
return ["core", "numeric", "partonomy"]
if profile == "core":
return ["core"]
return ["core", profile] # nocoverage
return ["core", profile]

def parse_log_level(self, log_level: str) -> bool: # nocoverage
"""
Expand Down Expand Up @@ -151,7 +151,7 @@ def main(self, control: Control, files: Sequence[str]) -> None:

control.ground()
control.solve()
elif self._solver == "fclingo": # nocoverage
elif self._solver == "fclingo":
self._propagator.register(control)
self._propagator.configure("max-int", str(self.config.max_int))
self._propagator.configure("min-int", str(self.config.min_int))
Expand All @@ -164,7 +164,7 @@ def main(self, control: Control, files: Sequence[str]) -> None:
pos = Position("<string>", 1, 1)
loc = Location(pos, pos)
for rule in hbt.rules_to_add:
bld.add(Rule(loc, rule[0], rule[1]))
bld.add(Rule(loc, rule[0], rule[1])) # nocoverage # Not sure when this is needed

control.add("base", [], THEORY)
control.ground([("base", [])])
Expand Down
56 changes: 56 additions & 0 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,59 @@ def test_attribute(self) -> None:
Test solving enumeration features with attributes with the clingo COOM core encoding.
"""
self.run_test(TESTS["attribute"])


class TestClingoPartonomy(TestCase):
"""
Test cases for the clingo COOM partonomy encoding.
"""

def run_test(self, test: dict[str, Any]) -> None:
"""Runs a clintest test with the clingo COOM partonomy encoding.
Args:
test (dict): The clintest test as a dictionary.
Should contain keys:
"test" (clintest.Test)
"files" (List[str] or "program" (str)
"""
program = test.get("program", None)
files = test.get("files", None)
run_test(test["test"], files=files, program=program, ctl_args=["0"], solver="clingo", profile="partonomy")

def test_structure(self) -> None:
"""
Test solving structure features with the clingo COOM partonomy encoding.
"""
self.run_test(TESTS["structure"])
self.run_test(TESTS["structure_optional"])
self.run_test(TESTS["structure_nested"])
self.run_test(TESTS["structure_nested_optional"])


class TestFclingoPartonomy(TestCase):
"""
Test cases for the fclingo COOM partonomy encoding.
"""

def run_test(self, test: dict[str, Any]) -> None:
"""Runs a clintest test with the fclingo COOM partonomy encoding.
Args:
test (dict): The clintest test as a dictionary.
Should contain keys:
"test" (clintest.Test)
"files" (List[str] or "program" (str)
"""
program = test.get("program", None)
files = test.get("files", None)
run_test(test["test"], files=files, program=program, ctl_args=["0"], solver="fclingo", profile="partonomy")

def test_structure(self) -> None:
"""
Test solving structure features with the fclingo COOM partonomy encoding.
"""
self.run_test(TESTS["structure"])
self.run_test(TESTS["structure_optional"])
self.run_test(TESTS["structure_nested"])
self.run_test(TESTS["structure_nested_optional"])
68 changes: 63 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
},
"enumeration": {
"test": AndTest(
Assert(Any(), Contains('val((color,((),0)),"Red")')),
Assert(Any(), Contains('val((color,((),0)),"Green")')),
Assert(Any(), Contains('val((color,((),0)),"Blue")')),
Assert(Exact(1), Contains('val((color,((),0)),"Red")')),
Assert(Exact(1), Contains('val((color,((),0)),"Green")')),
Assert(Exact(1), Contains('val((color,((),0)),"Blue")')),
Assert(Exact(3), True_()),
),
"program": """
Expand All @@ -82,8 +82,8 @@
},
"bool_enumeration": {
"test": AndTest(
Assert(Any(), Contains('val((boolean,((),0)),"True")')),
Assert(Any(), Contains('val((boolean,((),0)),"False")')),
Assert(Exact(1), Contains('val((boolean,((),0)),"True")')),
Assert(Exact(1), Contains('val((boolean,((),0)),"False")')),
Assert(Exact(2), True_()),
),
"program": """
Expand All @@ -105,4 +105,62 @@
option("Wheel", "W14").
attr_value("Wheel","W14",size,14).""",
},
"structure": {
"test": AndTest(
Assert(Exact(1), Contains('instance((wheel,((),0)),"Wheel")')),
Assert(Exact(1), True_()),
),
"program": """
structure(":root").
feature(":root",wheel,"Wheel",1,1).
structure("Wheel").""",
},
"structure_optional": {
"test": AndTest(
Assert(Exact(1), Contains('instance((basket,((),0)),"Basket")')),
Assert(Exact(2), True_()),
),
"program": """
structure(":root").
feature(":root",basket,"Basket",0,1).
structure("Basket").""",
},
"structure_nested": {
"test": AndTest(
Assert(
Exact(1),
SupersetOf({'instance((carrier,((),0)),"Carrier")', 'instance((bag,((carrier,((),0)),0)),"Bag")'}),
),
Assert(Exact(1), True_()),
),
"program": """
structure(":root").
feature(":root",carrier,"Carrier",1,1).
structure("Carrier").
feature("Carrier",bag,"Bag",1,1).
structure("Bag").""",
},
"structure_nested_optional": {
"test": AndTest(
Assert(Exact(3), Contains('instance((carrier,((),0)),"Carrier")')),
Assert(Exact(2), Contains('instance((bag,((carrier,((),0)),0)),"Bag")')),
Assert(
Exact(1),
SupersetOf(
{
'instance((carrier,((),0)),"Carrier")',
'instance((bag,((carrier,((),0)),0)),"Bag")',
'instance((bag,((carrier,((),0)),1)),"Bag")',
}
),
),
Assert(Exact(4), True_()),
),
"program": """
structure(":root").
feature(":root",carrier,"Carrier",0,1).
structure("Carrier").
feature("Carrier",bag,"Bag",0,2).
structure("Bag").""",
},
}

0 comments on commit bfefab2

Please sign in to comment.