Beispiel #1
0
 def test_deepcopy(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxDManager()
     b0 = PyBox(man,
                e,
                variables=[PyVar('x0')],
                intervals=[PyDoubleInterval(-2.5, 2.5)])
     b1 = deepcopy(b0)
     b2 = b0
     self.assertNotEqual(id(b0), id(b1))
     self.assertEqual(id(b0), id(b2))
Beispiel #2
0
 def test_top(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxDManager()
     self.assertFalse(PyBox.bottom(man, e).is_top())
     b1 = PyBox(man,
                e,
                variables=[PyVar('x0')],
                intervals=[PyDoubleInterval(-2.5, 2.5)])
     self.assertFalse(b1.is_bottom())
     b2 = PyBox(man,
                e,
                variables=[PyVar('y')],
                intervals=[PyMPQInterval(-5, 5, 2, 2)])
     self.assertFalse(b2.is_bottom())
     b3 = PyBox(man,
                e,
                variables=[PyVar('z')],
                intervals=[PyMPFRInterval(-2.5, 2.5)])
     self.assertFalse(b3.is_bottom())
     self.assertTrue(PyBox.top(man, e).is_top())
Beispiel #3
0
 def test_is_top(self):
     self.assertFalse(PyDoubleInterval().is_top())
     self.assertFalse(PyDoubleInterval(0, 0).is_top())
     self.assertFalse(PyDoubleInterval(0.0, 0.0).is_top())
     self.assertFalse(PyDoubleInterval(c_double(0), c_double(0)).is_top())
     self.assertFalse(
         PyDoubleInterval(c_double(0.0), c_double(0.0)).is_top())
     self.assertFalse(
         PyDoubleInterval(PyDoubleScalar(0), PyDoubleScalar(0)).is_top())
     self.assertFalse(
         PyDoubleInterval(PyDoubleScalar(0.0),
                          PyDoubleScalar(0.0)).is_top())
     self.assertFalse(PyDoubleInterval(-0.5, 0.5).is_top())
     self.assertFalse(
         PyDoubleInterval(c_double(-0.5), c_double(0.5)).is_top())
     self.assertFalse(
         PyDoubleInterval(PyDoubleScalar(-0.5),
                          PyDoubleScalar(0.5)).is_top())
     self.assertTrue(PyDoubleInterval.top().is_top())
     self.assertFalse(PyDoubleInterval.bottom().is_top())
Beispiel #4
0
 def test_cmp(self):
     self.assertTrue(PyDoubleInterval.bottom() < PyDoubleInterval())
     self.assertFalse(PyDoubleInterval() < PyDoubleInterval.bottom())
     self.assertTrue(PyDoubleInterval() < PyDoubleInterval(-0.5, 0.5))
     self.assertFalse(PyDoubleInterval(-0.5, 0.5) < PyDoubleInterval())
     self.assertTrue(PyDoubleInterval(-0.5, 0.5) < PyDoubleInterval.top())
     self.assertFalse(PyDoubleInterval.top() < PyDoubleInterval(-0.5, 0.5))
     self.assertFalse(PyDoubleInterval.bottom() == PyDoubleInterval())
     self.assertTrue(PyDoubleInterval() == PyDoubleInterval(0, 0))
     self.assertFalse(PyDoubleInterval() == PyDoubleInterval(-0.5, 0.5))
     self.assertTrue(
         PyDoubleInterval(-0.5, 0.5) == PyDoubleInterval(
             c_double(-0.5), c_double(0.5)))
     self.assertFalse(PyDoubleInterval(-0.5, 0.5) == PyDoubleInterval.top())
     self.assertFalse(PyDoubleInterval.bottom() > PyDoubleInterval())
     self.assertTrue(PyDoubleInterval() > PyDoubleInterval.bottom())
     self.assertFalse(PyDoubleInterval() > PyDoubleInterval(-0.5, 0.5))
     self.assertTrue(PyDoubleInterval(-0.5, 0.5) > PyDoubleInterval())
     self.assertFalse(PyDoubleInterval(-0.5, 0.5) > PyDoubleInterval.top())
     self.assertTrue(PyDoubleInterval.top() > PyDoubleInterval(-0.5, 0.5))
     self.assertTrue(
         PyDoubleInterval(-3, -1) <= PyDoubleInterval(
             PyDoubleScalar.init_infty(-1), PyDoubleScalar(-1)))
Beispiel #5
0
 def test_deepcopy(self):
     i0 = PyDoubleInterval(0, 0)
     i1 = deepcopy(i0)
     i2 = i0
     self.assertNotEqual(id(i0), id(i1))
     self.assertEqual(id(i0), id(i2))
Beispiel #6
0
 def test_init(self):
     self.assertEqual(str(PyDoubleInterval()), '[0.0,0.0]')
     self.assertEqual(str(PyDoubleInterval(0, 0)), '[0.0,0.0]')
     self.assertEqual(str(PyDoubleInterval(0.0, 0.0)), '[0.0,0.0]')
     self.assertEqual(str(PyDoubleInterval(c_double(0), c_double(0))),
                      '[0.0,0.0]')
     self.assertEqual(str(PyDoubleInterval(c_double(0.0), c_double(0.0))),
                      '[0.0,0.0]')
     self.assertEqual(
         str(PyDoubleInterval(PyDoubleScalar(0), PyDoubleScalar(0))),
         '[0.0,0.0]')
     self.assertEqual(
         str(PyDoubleInterval(PyDoubleScalar(0.0), PyDoubleScalar(0.0))),
         '[0.0,0.0]')
     self.assertEqual(str(PyDoubleInterval(-0.5, 0.5)), '[-0.5,0.5]')
     self.assertEqual(str(PyDoubleInterval(c_double(-0.5), c_double(0.5))),
                      '[-0.5,0.5]')
     self.assertEqual(
         str(PyDoubleInterval(PyDoubleScalar(-0.5), PyDoubleScalar(0.5))),
         '[-0.5,0.5]')
     self.assertEqual(str(PyDoubleInterval.top()), '[-inf,inf]')
     self.assertEqual(str(PyDoubleInterval.bottom()), '[1.0,-1.0]')
Beispiel #7
0
 def test_neg(self):
     self.assertEqual(-PyDoubleInterval.bottom(), PyDoubleInterval.bottom())
     self.assertEqual(-PyDoubleInterval(-1, 2), PyDoubleInterval(-2, 1))
     self.assertEqual(-PyDoubleInterval(), PyDoubleInterval(0, 0))
     self.assertEqual(-PyDoubleInterval(-0.5, 0.5),
                      PyDoubleInterval(c_double(-0.5), c_double(0.5)))
     self.assertEqual(-PyDoubleInterval(1, 2), PyDoubleInterval(-2, -1))
     self.assertEqual(-PyDoubleInterval.top(), PyDoubleInterval.top())
Beispiel #8
0
 def __init__(self, value_or_inf=0.0, sup=0.0):
     if isinstance(value_or_inf, (Coeff, PyDoubleInterval)):
         super().__init__(value_or_inf)
     else:
         super().__init__(PyDoubleInterval(value_or_inf, sup))
Beispiel #9
0
 def test_meet(self):
     e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')])
     man: PyManager = PyBoxDManager()
     b0 = PyBox.bottom(man, e)
     b1d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(-2.5, 0.0)])
     b1q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(-5, 0, 2, 1)])
     b1f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(-2.5, 0.0)])
     b2d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(0.0, 2.5)])
     b2q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(0, 5, 1, 2)])
     b2f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(0.0, 2.5)])
     b3d = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyDoubleInterval(0.0, 0.0)])
     b3q = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPQInterval(0, 0, 1, 1)])
     b3f = PyBox(man,
                 e,
                 variables=[PyVar('x0')],
                 intervals=[PyMPFRInterval(0.0, 0.0)])
     b4 = PyBox.top(man, e)
     self.assertTrue(b0.meet(b1d) == b0)
     self.assertTrue(b0.meet(b1q) == b0)
     self.assertTrue(b0.meet(b1f) == b0)
     self.assertTrue(b0.meet(b2d) == b0)
     self.assertTrue(b0.meet(b2q) == b0)
     self.assertTrue(b0.meet(b2f) == b0)
     self.assertTrue(b0.meet(b3d) == b0)
     self.assertTrue(b0.meet(b3q) == b0)
     self.assertTrue(b0.meet(b3f) == b0)
     self.assertTrue(b1d.meet(b2d) == b3d)
     self.assertTrue(b1d.meet(b3d) == b3d)
     self.assertTrue(b2d.meet(b3d) == b3d)
     self.assertTrue(b1q.meet(b2q) == b3q)
     self.assertTrue(b1q.meet(b3q) == b3q)
     self.assertTrue(b2q.meet(b3q) == b3q)
     self.assertTrue(b1f.meet(b2f) == b3f)
     self.assertTrue(b1f.meet(b3f) == b3f)
     self.assertTrue(b2f.meet(b3f) == b3f)
     self.assertTrue(b1d.meet(b4) == b1d)
     self.assertTrue(b1q.meet(b4) == b1q)
     self.assertTrue(b1f.meet(b4) == b1f)
     self.assertTrue(b2d.meet(b4) == b2d)
     self.assertTrue(b2q.meet(b4) == b2q)
     self.assertTrue(b2f.meet(b4) == b2f)
     self.assertTrue(b3d.meet(b4) == b3d)
     self.assertTrue(b3q.meet(b4) == b3q)
     self.assertTrue(b3f.meet(b4) == b3f)