def test_is_top(self): self.assertFalse(PyMPFRInterval(0, 0).is_top()) self.assertFalse(PyMPFRInterval(0.0, 0.0).is_top()) self.assertFalse( PyMPFRInterval(PyMPFRScalar(0), PyMPFRScalar(0)).is_top()) self.assertFalse( PyMPFRInterval(PyMPFRScalar(0.0), PyMPFRScalar(0.0)).is_top()) self.assertFalse(PyMPFRInterval(-0.5, 0.5).is_top()) self.assertFalse(PyMPFRInterval(PyMPFR(-0.5), PyMPFR(0.5)).is_top()) self.assertFalse( PyMPFRInterval(PyMPFRScalar(-0.5), PyMPFRScalar(0.5)).is_top()) self.assertTrue(PyMPFRInterval.top().is_top()) self.assertFalse(PyMPFRInterval.bottom().is_top())
def test_init(self): self.assertEqual(str(PyMPFRInterval(0, 0)), '[0.0,0.0]') self.assertEqual(str(PyMPFRInterval(0.0, 0.0)), '[0.0,0.0]') self.assertEqual(str(PyMPFRInterval(PyMPFRScalar(0), PyMPFRScalar(0))), '[0.0,0.0]') self.assertEqual( str(PyMPFRInterval(PyMPFRScalar(0.0), PyMPFRScalar(0.0))), '[0.0,0.0]') self.assertEqual(str(PyMPFRInterval(-0.5, 0.5)), '[-0.5,0.5]') self.assertEqual(str(PyMPFRInterval(PyMPFR(-0.5), PyMPFR(0.5))), '[-0.5,0.5]') self.assertEqual( str(PyMPFRInterval(PyMPFRScalar(-0.5), PyMPFRScalar(0.5))), '[-0.5,0.5]') self.assertEqual(str(PyMPFRInterval.top()), '[-inf,inf]') self.assertEqual(str(PyMPFRInterval.bottom()), '[1.0,-1.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())
def test_neg(self): self.assertEqual(-PyMPFRInterval.bottom(), PyMPFRInterval.bottom()) self.assertEqual(-PyMPFRInterval(-1, 2), PyMPFRInterval(-2, 1)) self.assertEqual(-PyMPFRInterval(0, 0), PyMPFRInterval(0, 0)) self.assertEqual(-PyMPFRInterval(-0.5, 0.5), PyMPFRInterval(PyMPFR(-0.5), PyMPFR(0.5))) self.assertEqual(-PyMPFRInterval(1, 2), PyMPFRInterval(-2, -1)) self.assertEqual(-PyMPFRInterval.top(), PyMPFRInterval.top())
def test_cmp(self): self.assertTrue(PyMPFRInterval.bottom() < PyMPFRInterval(0, 0)) self.assertFalse(PyMPFRInterval(0, 0) < PyMPFRInterval.bottom()) self.assertTrue(PyMPFRInterval(0, 0) < PyMPFRInterval(-0.5, 0.5)) self.assertFalse(PyMPFRInterval(-0.5, 0.5) < PyMPFRInterval(0, 0)) self.assertTrue(PyMPFRInterval(-0.5, 0.5) < PyMPFRInterval.top()) self.assertFalse(PyMPFRInterval.top() < PyMPFRInterval(-0.5, 0.5)) self.assertFalse(PyMPFRInterval.bottom() == PyMPFRInterval(0, 0)) self.assertTrue(PyMPFRInterval(0, 0) == PyMPFRInterval(0, 0)) self.assertFalse(PyMPFRInterval(0, 0) == PyMPFRInterval(-0.5, 0.5)) self.assertTrue( PyMPFRInterval(-0.5, 0.5) == PyMPFRInterval( PyMPFR(-0.5), PyMPFR(0.5))) self.assertFalse(PyMPFRInterval(-0.5, 0.5) == PyMPFRInterval.top()) self.assertFalse(PyMPFRInterval.bottom() > PyMPFRInterval(0, 0)) self.assertTrue(PyMPFRInterval(0, 0) > PyMPFRInterval.bottom()) self.assertFalse(PyMPFRInterval(0, 0) > PyMPFRInterval(-0.5, 0.5)) self.assertTrue(PyMPFRInterval(-0.5, 0.5) > PyMPFRInterval(0, 0)) self.assertFalse(PyMPFRInterval(-0.5, 0.5) > PyMPFRInterval.top()) self.assertTrue(PyMPFRInterval.top() > PyMPFRInterval(-0.5, 0.5))
def test_deepcopy(self): i0 = PyMPFRInterval(0, 0) i1 = deepcopy(i0) i2 = i0 self.assertNotEqual(id(i0), id(i1)) self.assertEqual(id(i0), id(i2))
def __init__(self, value_or_inf, sup=None, rounding: Rnd = Rnd.MPFR_RNDN): if isinstance(value_or_inf, (Coeff, PyMPFRInterval)): super().__init__(value_or_inf) else: super().__init__(PyMPFRInterval(value_or_inf, sup, rounding))
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)