def test_max_diam(self): b = Box([x, y]) b[x] = Interval(0.1, 0.2) b[y] = Interval(1, 2) (diam, idx) = b.MaxDiam() self.assertEqual(idx, 1) self.assertEqual(b[idx].diam(), 1)
def to_dictionary(self): b = Box([x]) b.Add(y) b.Add(z, 2, 5) d = dict(b) self.assertEqual(d[y], Interval()) self.assertEqual(d[z], Interval(2, 5))
def test_unsat(self): result = CheckSatisfiability(f_unsat, 0.001) self.assertEqual(result, None) b = Box([x, y, z]) b_copy = Box([x, y, z]) result = CheckSatisfiability(f_unsat, 0.001, b) self.assertEqual(result, False) self.assertEqual(b, b_copy) # Unchanged
def test_inplace_union(self): b1 = Box([x, y]) b1[x] = Interval(1, 3) b1[y] = Interval(1, 2) b2 = Box([x, y]) b2[x] = Interval(2, 4) b2[y] = Interval(3, 5) b2.InplaceUnion(b1) self.assertEqual(b2[x], Interval(1, 4)) self.assertEqual(b2[y], Interval(1, 5))
def test_delta_sat(self): result = CheckSatisfiability(f_sat, 0.001) self.assertEqual(type(result), Box) b = Box([x, y, z]) result = CheckSatisfiability(f_sat, 0.001, b) self.assertEqual(result, True) self.assertTrue(b[x].diam() < 0.1) self.assertTrue(b[y].diam() < 0.1) self.assertTrue(b[z].diam() < 0.1)
def test_keys_values_items(self): b = Box([x]) b.Add(y) b.Add(z, 2, 5) self.assertEqual(b.keys(), [x, y, z]) self.assertEqual( b.values(), [Interval(-inf, inf), Interval(-inf, inf), Interval(2, 5)]) self.assertEqual(b.items(), [(x, Interval(-inf, inf)), (y, Interval(-inf, inf)), (z, Interval(2, 5))])
def test_add(self): b = Box([x]) b.Add(y) b.Add(z, 2, 5) self.assertEqual(b[y], Interval()) self.assertEqual(b[z], Interval(2, 5))
def test_bisect_variable(self): b = Box([x, y, z]) (b1, b2) = b.bisect(x) self.assertEqual(b1[x].ub(), 0) self.assertEqual(b2[x].lb(), 0)
def test_bisect_int(self): b = Box([x, y, z]) (b1, b2) = b.bisect(0) self.assertEqual(b1[0].ub(), 0) self.assertEqual(b2[0].lb(), 0)
def test_index(self): b = Box([x, y, z]) self.assertEqual(b.index(x), 0)
def test_get_set_item_int(self): b = Box([x, y, z]) self.assertEqual(b.variable(0), x) b[0] = Interval(3, 4) self.assertEqual(b[0], Interval(3, 4))
def test_get_set_item_variable(self): b = Box([x, y, z]) b[x] = Interval(3, 4) self.assertEqual(b[x], Interval(3, 4))
def test_string(self): b = Box([x]) self.assertEqual(str(b), "x : [ ENTIRE ]") self.assertEqual(repr(b), '<Box "x : [ ENTIRE ]">')
def test_size_empty_set_empty(self): b = Box([x, y, z]) self.assertEqual(b.size(), 3) self.assertFalse(b.empty()) b.set_empty() self.assertTrue(b.empty())
def test_copy_constructor(self): b1 = Box([x, y, z]) b2 = Box([x, y, z]) self.assertEqual(b1, b2) b2.set_empty() self.assertNotEqual(b1, b2)
def test_minimize2(self): b = Box([x]) result = Minimize(objective, constraint, 0.00001, b) self.assertTrue(result) self.assertAlmostEqual(b[x].mid(), -1.5, places=2)