def test_over_constraint(self): """ Test over constraint problem """ r1 = BoxStyle() r2 = BoxStyle() r3 = BoxStyle() r1.min_size = Size(10, 10) r2.min_size = Size(20, 5) s = Solver() s.add(TopEq(r1, r2)) s.add(MinVDist(r1, r2, 20)) self.assertRaises(SolverError, s.solve)
def test_bottom_eq(self): """ Test bottom eq constraint """ r1 = BoxStyle() r2 = BoxStyle() r1.min_size = Size(10, 10) r2.min_size = Size(20, 5) r1.size = Size(10, 10) r2.size = Size(20, 5) s = Solver() s.add(MinSize(r1)) s.add(MinSize(r2)) s.add(BottomEq(r1, r2)) s.solve() self.assertTrue(r1.size.width >= 10) self.assertTrue(r1.size.height >= 10) self.assertTrue(r2.size.width >= 20) self.assertTrue(r2.size.height >= 5) self.assertEquals(0, r1.pos.y) self.assertEquals(5, r2.pos.y)
def test_solver(self): """ Test (simply) constraint solver """ r1 = BoxStyle() r2 = BoxStyle() r3 = BoxStyle() r1.min_size = Size(10, 10) r2.min_size = Size(20, 5) r3.min_size = Size(5, 15) s = Solver() s.add(MinSize(r1)) s.add(MinSize(r2)) s.add(MinSize(r3)) s.add(TopEq(r1, r2)) s.add(MinHDist(r2, r3, 10)) s.solve() self.assertTrue(r1.size.width >= 10) self.assertTrue(r1.size.height >= 10) self.assertTrue(r2.size.width >= 20) self.assertTrue(r2.size.height >= 5) self.assertTrue(r3.size.width >= 5) self.assertTrue(r3.size.height >= 15) self.assertEquals(40, r1.size.height) self.assertEquals(40, r2.size.height) self.assertTrue(r3.pos.x - r2.pos.x - r2.size.width >= 10)