Skip to content

Commit

Permalink
added preprocessing tests for COOM count and sum
Browse files Browse the repository at this point in the history
  • Loading branch information
nrueh committed Dec 20, 2024
1 parent a0e1199 commit 233ca6f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
11 changes: 11 additions & 0 deletions examples/tests/preprocess/count.lp
Original file line number Diff line number Diff line change
@@ -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).
11 changes: 11 additions & 0 deletions examples/tests/preprocess/sum.lp
Original file line number Diff line number Diff line change
@@ -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).
55 changes: 55 additions & 0 deletions tests/clintests/tests_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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").',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 233ca6f

Please sign in to comment.