diff --git a/tests/test_solve.py b/tests/test_solve.py index d20cade..8b42b5e 100644 --- a/tests/test_solve.py +++ b/tests/test_solve.py @@ -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") @@ -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") @@ -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") @@ -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") @@ -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: """ diff --git a/tests/tests.py b/tests/tests.py index 5f30ca4..2c81e34 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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": """ @@ -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": { @@ -247,6 +293,7 @@ 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": { @@ -254,9 +301,9 @@ def holds_for(self, model: Model) -> bool: "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": {