Skip to content

Commit

Permalink
added tests for (valid) user input
Browse files Browse the repository at this point in the history
  • Loading branch information
nrueh committed Dec 2, 2024
1 parent 889b30b commit 288492c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 40 deletions.
60 changes: 22 additions & 38 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ class TestClingoCore(TestCase):
def run_test(self, test_name: str) -> None:
"""
Runs a clintest test with the clingo COOM core encoding.
Args:
test (dict): The clintest test as a dictionary.
Should contain keys:
"test" (clintest.Test)
"files" (List[str] or "program" (str)
"""
test, program, files = unpack_test(test_name)
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo")
Expand Down Expand Up @@ -87,14 +81,8 @@ class TestFclingoCore(TestCase):
"""

def run_test(self, test_name: str) -> None:
"""Runs a clintest test with the fclingo COOM core encoding.
Args:
test (dict): The clintest test as a dictionary.
Should contain keys:
"test" (clintest.Test)
"files" (List[str] or "program" (str)
"ftest" (Optional[clintest.Test]): A clintest for fclingo
"""
Runs a clintest test with the fclingo COOM core encoding.
"""
test, program, files = unpack_test(test_name, fclingo=True)
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo")
Expand Down Expand Up @@ -140,13 +128,8 @@ class TestClingoPartonomy(TestCase):
"""

def run_test(self, test_name: str) -> 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)
"""
Runs a clintest test with the clingo COOM partonomy encoding.
"""
test, program, files = unpack_test(test_name)
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo")
Expand Down Expand Up @@ -187,13 +170,8 @@ class TestFclingoPartonomy(TestCase):
"""

def run_test(self, test_name: str) -> 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)
"""
Runs a clintest test with the fclingo COOM partonomy encoding.
"""
test, program, files = unpack_test(test_name, fclingo=True)
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo")
Expand All @@ -214,27 +192,33 @@ class TestUserInput(TestCase):
"""

def run_test(self, test_name: str) -> None:
"""Runs a clintest test for the user input check.
Args:
test (dict): The clintest test as a dictionary.
Should contain keys:
"test" (clintest.Test)
"files" (List[str] or "program" (str)
"""
Runs a clintest test with the COOM user input.
"""
test, program, files = unpack_test(test_name)
run_test(test, files=files, program=program)
run_test(test, files=files, program=program, ctl_args=["0"])

def user_check(self, test: str, expected_msg: str) -> None:
"""
Runs a test checking the user input for validity.
"""
with self.assertRaises(ValueError) as ctx:
self.run_test(test)
self.assertEqual(str(ctx.exception), expected_msg)

def test_set(self) -> None:
pass
"""
Test setting a value by the user.
"""
self.run_test("set_discrete")
self.run_test("set_num")

def test_add(self) -> None:
pass
"""
Test adding an object by the user.
"""
self.run_test("add")
self.run_test("add2")

def test_checks(self) -> None:
"""
Expand Down
51 changes: 49 additions & 2 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,51 @@ def holds_for(self, model: Model) -> bool:
coom_feature("Carrier","bag","Bag",0,2).
coom_structure("Bag").""",
},
"set_discrete": {
"test": AndTest(Assert(Exact(1), True_()), Assert(Any(), Contains('value("root.color[0]","Yellow")'))),
"program": """
coom_structure("product").
coom_feature("product","color","Color",1,1).
coom_enumeration("Color").
coom_option("Color","Red").
coom_option("Color","Yellow").
coom_user_value("root.color[0]","Yellow").""",
},
"set_num": {
"test": AndTest(Assert(Exact(1), True_()), Assert(Any(), Contains('value("root.size[0]",5)'))),
"program": """
coom_structure("product").
coom_feature("product","size","num",1,1).
coom_range("product","size",1,10).
coom_user_value("root.size[0]",5).""",
},
"add": {
"test": AndTest(
Assert(Exact(2), True_()),
Assert(Any(), Contains('include("root.bag[0]")')),
Assert(Exact(1), Contains('include("root.bag[1]")')),
),
"program": """
coom_structure("product").
coom_feature("product","bag","Bag",0,2).
coom_structure("Bag").
coom_user_include("root.bag[0]").""",
},
"add2": {
"test": AndTest(
Assert(Exact(1), True_()),
Assert(Any(), Contains('include("root.bag[0]")')),
Assert(Any(), Contains('include("root.bag[1]")')),
),
"program": """
coom_structure("product").
coom_feature("product","bag","Bag",0,2).
coom_structure("Bag").
coom_user_include("root.bag[0]").
coom_user_include("root.bag[1]").""",
},
"set_invalid_variable": {
"test": True_,
"program": """
Expand All @@ -239,6 +284,7 @@ def holds_for(self, model: Model) -> bool:
coom_structure("product").
coom_feature("product","basket","Basket",1,1).
coom_structure("Basket").
coom_user_value("root.basket[0]","Yellow").""",
},
"add_invalid_type": {
Expand All @@ -247,16 +293,17 @@ def holds_for(self, model: Model) -> bool:
coom_structure("product").
coom_feature("product","basket","Basket",1,1).
coom_enumeration("Basket").
coom_user_include("root.basket[0]").""",
},
"set_invalid_value_discrete": {
"test": True_,
"program": """
coom_structure("product").
coom_feature("product","color","Color",1,1).
coom_enumeration("Color").
coom_option("Color", "Red").
coom_option("Color","Red").
coom_user_value("root.color[0]","Yellow").""",
},
"set_invalid_value_num": {
Expand Down

0 comments on commit 288492c

Please sign in to comment.