Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceBleukx committed Oct 17, 2023
1 parent 3836388 commit f61e861
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/test_tools_mus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from unittest import TestCase

from cpmpy import *
import cpmpy as cp
from cpmpy.tools.mus import mus, mus_naive, quickxplain, quickxplain_naive

class MusTests(TestCase):
Expand All @@ -12,7 +12,7 @@ def __init__(self, *args, **kwargs):
self.naive_func = mus_naive

def test_circular(self):
x = intvar(0, 3, shape=4, name="x")
x = cp.intvar(0, 3, shape=4, name="x")
# circular "bigger then", UNSAT
cons = [
x[0] > x[1],
Expand All @@ -31,7 +31,7 @@ def test_bug_191(self):
Original Bug request: https://github.com/CPMpy/cpmpy/issues/191
When assum is a single boolvar and candidates is a list (of length 1), it fails.
"""
bv = boolvar(name="x")
bv = cp.boolvar(name="x")
hard = [~bv]
soft = [bv]

Expand All @@ -45,8 +45,8 @@ def test_bug_191_many_soft(self):
Checking whether bugfix 191 doesn't break anything in the MUS tool chain,
when the number of soft constraints > 1.
"""
x = intvar(-9, 9, name="x")
y = intvar(-9, 9, name="y")
x = cp.intvar(-9, 9, name="x")
y = cp.intvar(-9, 9, name="y")
hard = [x > 2]
soft = [
x + y < 6,
Expand All @@ -59,8 +59,8 @@ def test_bug_191_many_soft(self):
self.assertEqual(set(mus_naive_cons), set(soft))

def test_wglobal(self):
x = intvar(-9, 9, name="x")
y = intvar(-9, 9, name="y")
x = cp.intvar(-9, 9, name="x")
y = cp.intvar(-9, 9, name="y")

cons = [
x < 0,
Expand All @@ -72,17 +72,17 @@ def test_wglobal(self):
(y >= 0) | (x >= 0),
(y < 0) | (x < 0),
(y > 0) | (x < 0),
AllDifferent(x,y)
cp.AllDifferent(x,y)
]

# non-determinstic
#self.assertEqual(set(mus(cons)), set(cons[1:3]))
ms = self.mus_func(cons)
self.assertLess(len(ms), len(cons))
self.assertFalse(Model(ms).solve())
self.assertFalse(cp.Model(ms).solve())
ms = self.naive_func(cons)
self.assertLess(len(ms), len(cons))
self.assertFalse(Model(ms).solve())
self.assertFalse(cp.Model(ms).solve())
# self.assertEqual(set(self.naive_func(cons)), set(cons[:2]))


Expand All @@ -95,12 +95,12 @@ def __init__(self, *args, **kwargs):

def test_prefered(self):

a,b,c,d = [boolvar(name=n) for n in "abcd"]
a,b,c,d = [cp.boolvar(name=n) for n in "abcd"]

mus1 = [b,d]
mus2 = [a,b,c]

hard = [~all(mus1), ~all(mus2)]
hard = [~cp.all(mus1), ~cp.all(mus2)]
subset = self.mus_func([a,b,c,d],hard)
self.assertSetEqual(set(subset), {a,b,c})
subset2 = self.mus_func([d,c,b,a], hard)
Expand Down

0 comments on commit f61e861

Please sign in to comment.