Ejemplo n.º 1
0
 def test_top_and_bottom(self):
     self.assertEqual(self.top, FloatInterval([-inf, inf]))
     self.assertNotEqual(self.top, FloatInterval([2, inf]))
     self.assertNotEqual(self.top, FloatInterval([-inf, 2]))
     self.assertEqual(self.bottom + self.int14, self.bottom)
     self.assertEqual(self.int14 + self.bottom, self.bottom)
     self.assertEqual(self.top + self.int14, self.top)
     self.assertEqual(self.int14 + self.top, self.top)
Ejemplo n.º 2
0
class TestInterval(unittest.TestCase):
    """Unittesting for :class:`soap.semantics.FloatInterval`."""
    def setUp(self):
        self.bottom = FloatInterval(bottom=True)
        self.top = FloatInterval(top=True)
        self.int14 = FloatInterval([1, 4])
        self.int34 = FloatInterval([3, 4])
        self.int29 = FloatInterval([2, 9])

    def test_top_and_bottom(self):
        self.assertEqual(self.top, FloatInterval([-inf, inf]))
        self.assertNotEqual(self.top, FloatInterval([2, inf]))
        self.assertNotEqual(self.top, FloatInterval([-inf, 2]))
        self.assertEqual(self.bottom + self.int14, self.bottom)
        self.assertEqual(self.int14 + self.bottom, self.bottom)
        self.assertEqual(self.top + self.int14, self.top)
        self.assertEqual(self.int14 + self.top, self.top)

    def test_operators(self):
        self.assertEqual(self.int14 + self.int29, FloatInterval([3, 13]))
        self.assertEqual(self.int14 - self.int29, FloatInterval([-8, 2]))
        self.assertEqual(self.int14 * self.int29, FloatInterval([2, 36]))
        self.assertEqual(self.int14 / self.int29, FloatInterval([1 / 9, 2]))
        self.assertEqual(-self.int14, FloatInterval([-4, -1]))

    def test_coercion(self):
        self.assertEqual(1 + self.int29, FloatInterval([3, 10]))
        self.assertEqual(self.int29 + 1, FloatInterval([3, 10]))
        self.assertEqual(1 - self.int29, FloatInterval([-8, -1]))
        self.assertEqual(self.int29 - 1, FloatInterval([1, 8]))
        self.assertEqual(2 * self.int29, FloatInterval([4, 18]))
        self.assertEqual(self.int29 * 2, FloatInterval([4, 18]))
        self.assertEqual(2 / self.int29, FloatInterval([2 / 9, 1]))
        self.assertEqual(self.int29 / 2, FloatInterval([1, 9 / 2]))

    def test_order(self):
        self.assertTrue(self.bottom <= self.int14)
        self.assertFalse(self.int14 <= self.bottom)
        self.assertFalse(self.top <= self.int14)
        self.assertTrue(self.bottom <= self.int14)
        self.assertFalse(self.int14 <= self.int29)
        self.assertTrue(self.int34 <= self.int14)

    def test_join(self):
        self.assertEqual(self.int14 | self.int34, self.int14)
        self.assertEqual(self.int14 | self.int29, FloatInterval([1, 9]))

    def test_meet(self):
        self.assertEqual(self.int14 & self.int34, self.int34)
        self.assertEqual(self.int14 & self.int29, FloatInterval([2, 4]))

    def test_widen(self):
        self.assertEqual(self.int34.widen(self.int14), FloatInterval([-inf,
                                                                      4]))
        self.assertEqual(self.int14.widen(self.int34), self.int14)
        self.assertEqual(self.int34.widen(self.int29), self.top)
Ejemplo n.º 3
0
 def setUp(self):
     self.interval = [2, 3]
     self.const = 4
     self.integer = self.const
     self.float = float(self.const)
     self.integer_interval = IntegerInterval(self.interval)
     self.float_interval = FloatInterval(self.interval)
     self.error = ErrorSemantics(self.interval)
     self.interval_tests = [
         (self.integer_interval, self.float_interval, FloatInterval),
         (self.float_interval, self.integer_interval, FloatInterval),
         (self.integer_interval, self.error, ErrorSemantics),
         (self.error, self.integer_interval, ErrorSemantics),
         (self.float_interval, self.error, ErrorSemantics),
         (self.error, self.float_interval, ErrorSemantics),
     ]
     self.const_tests = [
         (self.integer_interval, self.integer, IntegerInterval),
         (self.integer, self.integer_interval, IntegerInterval),
         (self.integer_interval, self.float, FloatInterval),
         (self.float, self.integer_interval, FloatInterval),
         (self.float_interval, self.integer, FloatInterval),
         (self.integer, self.float_interval, FloatInterval),
         (self.float_interval, self.float, FloatInterval),
         (self.float, self.float_interval, FloatInterval),
         (self.error, self.integer, ErrorSemantics),
         (self.integer, self.error, ErrorSemantics),
         (self.error, self.float, ErrorSemantics),
         (self.float, self.error, ErrorSemantics),
     ]
Ejemplo n.º 4
0
 def test_coercion(self):
     self.assertEqual(1 + self.int29, FloatInterval([3, 10]))
     self.assertEqual(self.int29 + 1, FloatInterval([3, 10]))
     self.assertEqual(1 - self.int29, FloatInterval([-8, -1]))
     self.assertEqual(self.int29 - 1, FloatInterval([1, 8]))
     self.assertEqual(2 * self.int29, FloatInterval([4, 18]))
     self.assertEqual(self.int29 * 2, FloatInterval([4, 18]))
     self.assertEqual(2 / self.int29, FloatInterval([2 / 9, 1]))
     self.assertEqual(self.int29 / 2, FloatInterval([1, 9 / 2]))
Ejemplo n.º 5
0
 def test_widen(self):
     self.assertEqual(self.int34.widen(self.int14), FloatInterval([-inf,
                                                                   4]))
     self.assertEqual(self.int14.widen(self.int34), self.int14)
     self.assertEqual(self.int34.widen(self.int29), self.top)
Ejemplo n.º 6
0
 def test_meet(self):
     self.assertEqual(self.int14 & self.int34, self.int34)
     self.assertEqual(self.int14 & self.int29, FloatInterval([2, 4]))
Ejemplo n.º 7
0
 def test_join(self):
     self.assertEqual(self.int14 | self.int34, self.int14)
     self.assertEqual(self.int14 | self.int29, FloatInterval([1, 9]))
Ejemplo n.º 8
0
 def test_operators(self):
     self.assertEqual(self.int14 + self.int29, FloatInterval([3, 13]))
     self.assertEqual(self.int14 - self.int29, FloatInterval([-8, 2]))
     self.assertEqual(self.int14 * self.int29, FloatInterval([2, 36]))
     self.assertEqual(self.int14 / self.int29, FloatInterval([1 / 9, 2]))
     self.assertEqual(-self.int14, FloatInterval([-4, -1]))
Ejemplo n.º 9
0
 def setUp(self):
     self.bottom = FloatInterval(bottom=True)
     self.top = FloatInterval(top=True)
     self.int14 = FloatInterval([1, 4])
     self.int34 = FloatInterval([3, 4])
     self.int29 = FloatInterval([2, 9])