From 233ca6f183d6fed1e440f3f1d3d1f8b0a7344d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20R=C3=BChling?= Date: Fri, 20 Dec 2024 18:41:20 +0100 Subject: [PATCH] added preprocessing tests for COOM count and sum --- examples/tests/preprocess/count.lp | 11 ++++++ examples/tests/preprocess/sum.lp | 11 ++++++ tests/clintests/tests_preprocess.py | 55 +++++++++++++++++++++++++++++ tests/test_preprocess.py | 3 +- 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 examples/tests/preprocess/count.lp create mode 100644 examples/tests/preprocess/sum.lp diff --git a/examples/tests/preprocess/count.lp b/examples/tests/preprocess/count.lp new file mode 100644 index 0000000..5f1648e --- /dev/null +++ b/examples/tests/preprocess/count.lp @@ -0,0 +1,11 @@ +coom_structure("product"). +coom_feature("product","bag","Bag",0,3). +coom_structure("Bag"). + +coom_behavior(0). +coom_context(0,"product"). +coom_require(0,"count(bag)<=2"). +coom_binary("count(bag)<=2","count(bag)","<=","2"). +coom_function("product","count(bag)","count","bag"). +coom_path("bag",0,"bag"). +coom_number("2",2). diff --git a/examples/tests/preprocess/sum.lp b/examples/tests/preprocess/sum.lp new file mode 100644 index 0000000..28aada7 --- /dev/null +++ b/examples/tests/preprocess/sum.lp @@ -0,0 +1,11 @@ +coom_structure("product"). +coom_feature("product","x","num",0,3). +coom_range("product","x",0,10). + +coom_behavior(0). +coom_context(0,"product"). +coom_require(0,"sum(x)<=10"). +coom_binary("sum(x)<=10","sum(x)","<=","10"). +coom_function("product","sum(x)","sum","x"). +coom_path("x",0,"x"). +coom_number("10",10). diff --git a/tests/clintests/tests_preprocess.py b/tests/clintests/tests_preprocess.py index cd1f41a..1e82122 100644 --- a/tests/clintests/tests_preprocess.py +++ b/tests/clintests/tests_preprocess.py @@ -986,6 +986,61 @@ ), "files": ["parentheses.lp"], }, + "count": { + "test": SingleModelEquals( + { + 'part("product")', + 'part("Bag")', + 'constraint(("root.bag",0),"lowerbound")', + 'constraint((0,"count(root.bag)<=2"),"boolean")', + 'index("root.bag[0]",0)', + 'index("root.bag[1]",1)', + 'index("root.bag[2]",2)', + 'number("2",2)', + 'parent("root.bag[0]","root")', + 'parent("root.bag[1]","root")', + 'parent("root.bag[2]","root")', + 'set("root.bag","root.bag[0]")', + 'set("root.bag","root.bag[1]")', + 'set("root.bag","root.bag[2]")', + 'type("root","product")', + 'type("root.bag[0]","Bag")', + 'type("root.bag[1]","Bag")', + 'type("root.bag[2]","Bag")', + 'function("count(root.bag)","count","root.bag")', + 'binary("count(root.bag)<=2","count(root.bag)","<=","2")', + } + ), + "files": ["count.lp"], + }, + "sum": { + "test": SingleModelEquals( + { + 'integer("product.x")', + 'part("product")', + 'constraint(("root.x",0),"lowerbound")', + 'constraint((0,"sum(root.x)<=10"),"boolean")', + 'index("root.x[0]",0)', + 'index("root.x[1]",1)', + 'index("root.x[2]",2)', + 'number("10",10)', + 'parent("root.x[0]","root")', + 'parent("root.x[1]","root")', + 'parent("root.x[2]","root")', + 'set("root.x","root.x[0]")', + 'set("root.x","root.x[1]")', + 'set("root.x","root.x[2]")', + 'type("root","product")', + 'type("root.x[0]","product.x")', + 'type("root.x[1]","product.x")', + 'type("root.x[2]","product.x")', + 'function("sum(root.x)","sum","root.x")', + 'range("product.x",0,10)', + 'binary("sum(root.x)<=10","sum(root.x)","<=","10")', + } + ), + "files": ["sum.lp"], + }, "set_constant": { "test": SingleModelEquals({'user_value("root.color[0]","Yellow")'}), "program": 'coom_user_value("root.color[0]","Yellow").', diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py index a382144..0ffd3b8 100644 --- a/tests/test_preprocess.py +++ b/tests/test_preprocess.py @@ -79,7 +79,8 @@ def test_numerics(self) -> None: self.run_test("simple_arithmetic_minus_default_left") self.run_test("parentheses") - # Numerical functions (aggregates) + self.run_test("count") + self.run_test("sum") def test_user_input(self) -> None: """