def test_property(self): x = -200 y = -100 width = 600 height = 300 rect = DOMRect(x, y, width, height) self.assertFalse(rect.isempty()) self.assertTrue(rect.isvalid()) self.assertEqual(x, rect.x) self.assertEqual(x, rect.left) self.assertEqual(y, rect.y) self.assertEqual(y, rect.top) self.assertEqual(x + width, rect.right) self.assertEqual(y + height, rect.bottom) self.assertEqual(width, rect.width) self.assertEqual(height, rect.height) x = 100 y = 200 width = 300 height = 600 rect.x = x rect.y = y rect.width = width rect.height = height self.assertFalse(rect.isempty()) self.assertTrue(rect.isvalid()) self.assertEqual(x, rect.x) self.assertEqual(x, rect.left) self.assertEqual(y, rect.y) self.assertEqual(y, rect.top) self.assertEqual(x + width, rect.right) self.assertEqual(y + height, rect.bottom) self.assertEqual(width, rect.width) self.assertEqual(height, rect.height)
def test_iand(self): # a: (100, 100) - (200, 300) # b: (150, 150) - (200, 200) ax = 100 ay = 100 aw = 100 ah = 200 bx = 150 by = 150 bw = 50 bh = 50 cx = 150 cy = 150 cw = 50 ch = 50 a = DOMRect(ax, ay, aw, ah) b = DOMRectReadOnly(bx, by, bw, bh) a &= b self.assertIsInstance(a, DOMRect) self.assertEqual(cx, a.x) self.assertEqual(cy, a.y) self.assertEqual(cw, a.width) self.assertEqual(ch, a.height) self.assertEqual(bx, b.x) self.assertEqual(by, b.y) self.assertEqual(bw, b.width) self.assertEqual(bh, b.height)
def test_ior(self): ax = 100 ay = 100 aw = 100 ah = 200 bx = 150 by = 150 bw = 50 bh = 50 cx = min(ax, bx) cy = min(ay, by) cw = max(ax + aw, bx + bw) - min(ax, bx) ch = max(ay + ah, by + bh) - min(ay, by) a = DOMRect(ax, ay, aw, ah) b = DOMRectReadOnly(bx, by, bw, bh) a |= b self.assertIsInstance(a, DOMRect) self.assertEqual(cx, a.x) self.assertEqual(cy, a.y) self.assertEqual(cw, a.width) self.assertEqual(ch, a.height) self.assertEqual(bx, b.x) self.assertEqual(by, b.y) self.assertEqual(bw, b.width) self.assertEqual(bh, b.height)
def test_and01(self): # invalid rectangle AND valid rectangle w = 10 h = 20 xb = 100 yb = 100 a = DOMRect() b = DOMRect(xb, yb, w, h) c = a & b expected_x = None expected_y = None expected_w = 0 expected_h = 0 self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_tojson(self): x = -200 y = -100 width = 600 height = 300 rect = DOMRect(x, y, width, height) json = rect.tojson() self.assertEqual(x, json['x']) self.assertEqual(y, json['y']) self.assertEqual(width, json['width']) self.assertEqual(height, json['height']) o = DOMRect.from_rect(json) self.assertEqual(o, rect) self.assertEqual(x, o.x) self.assertEqual(y, o.y) self.assertEqual(width, o.width) self.assertEqual(height, o.height)
def test_unite_point01(self): # left-upper w = 10 h = 20 xa = 100 ya = 100 xb = xa - w / 2 yb = ya - h / 2 a = DOMRect(xa, ya, w, h) c = a.unite(xb, yb) expected_x = xb expected_y = yb expected_w = w + w / 2 expected_h = h + h / 2 self.assertEqual(expected_x, c.x, msg=(a, c)) self.assertEqual(expected_y, c.y, msg=(a, c)) self.assertEqual(expected_w, c.width, msg=(a, c)) self.assertEqual(expected_h, c.height, msg=(a, c))
def test_unite_point03(self): # upper-right w = 10 h = 20 xa = 100 ya = 100 xb = xa + w yb = ya - h / 2 a = DOMRect(xa, ya, w, h) c = a.unite(xb, yb) expected_x = xa expected_y = yb expected_w = w expected_h = h + h / 2 self.assertEqual(expected_x, c.x, msg=(a, c)) self.assertEqual(expected_y, c.y, msg=(a, c)) self.assertEqual(expected_w, c.width, msg=(a, c)) self.assertEqual(expected_h, c.height, msg=(a, c))
def test_unite_point12(self): # right-lower w = 10 h = 20 xa = 100 ya = 100 xb = xa + w + w / 2 yb = ya + h + h / 2 a = DOMRect(xa, ya, w, h) c = a.unite(xb, yb) expected_x = xa expected_y = ya expected_w = w + w / 2 expected_h = h + h / 2 self.assertEqual(expected_x, c.x, msg=(a, c)) self.assertEqual(expected_y, c.y, msg=(a, c)) self.assertEqual(expected_w, c.width, msg=(a, c)) self.assertEqual(expected_h, c.height, msg=(a, c))
def test_and18(self): # right-lower w = 10 h = 20 xa = 100 ya = 100 xb = xa + w yb = ya + h / 2 a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a & b expected_x = xa expected_y = ya expected_w = w expected_h = h self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_and16(self): # lower overlapped w = 10 h = 20 xa = 100 ya = 100 xb = xa yb = ya + h / 2 a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a & b expected_x = xa expected_y = ya + h / 2 expected_w = w expected_h = h / 2 self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_and11(self): # right overlapped w = 10 h = 20 xa = 100 ya = 100 xb = xa + w / 2 yb = ya a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a & b expected_x = xa + w / 2 expected_y = ya expected_w = w / 2 expected_h = h self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_and10(self): # same position w = 10 h = 20 xa = 100 ya = 100 xb = xa yb = ya a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a & b expected_x = xa expected_y = ya expected_w = w expected_h = h self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_unite_rect15(self): # lower w = 10 h = 20 xa = 100 ya = 100 xb = xa yb = ya + h a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a | b expected_x = xa expected_y = ya expected_w = w expected_h = h + h self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_unite_rect02(self): # left-upper overlapped w = 10 h = 20 xa = 100 ya = 100 xb = xa - w / 2 yb = ya - h / 2 a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a | b expected_x = xb expected_y = yb expected_w = w + w / 2 expected_h = h + h / 2 self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_unite_rect11(self): # right w = 10 h = 20 xa = 100 ya = 100 xb = xa + w yb = ya a = DOMRect(xa, ya, w, h) b = DOMRect(xb, yb, w, h) c = a | b expected_x = xa expected_y = ya expected_w = w * 2 expected_h = h self.assertEqual(expected_x, c.x, msg=(a, b, c)) self.assertEqual(expected_y, c.y, msg=(a, b, c)) self.assertEqual(expected_w, c.width, msg=(a, b, c)) self.assertEqual(expected_h, c.height, msg=(a, b, c))
def test_read_only_ior(self): a = DOMRectReadOnly() b = DOMRectReadOnly() a |= b self.assertIsNone(a) a = DOMRectReadOnly() b = DOMRect() a |= b self.assertIsNone(a)
def test_united_valid_invalid(self): a = DOMRect(30, 50, 100, 200) b = DOMRect() c = a.unite(b.x, b.y, b.width, b.height) self.assertTrue(not c.isempty()) self.assertTrue(c.isvalid()) self.assertEqual((30, 50, 100, 200), (a.x, a.y, a.width, a.height)) self.assertTrue(b.isempty()) self.assertTrue(not b.isvalid())
def test_intersect03(self): a = DOMRect(30, 50, 100, 200) b = DOMRect() c = a.intersect(b) self.assertTrue(not c.isempty()) self.assertTrue(c.isvalid()) self.assertEqual((30, 50, 100, 200), (c.x, c.y, c.width, c.height)) self.assertEqual((30, 50, 100, 200), (a.x, a.y, a.width, a.height)) self.assertTrue(b.isempty()) self.assertTrue(not b.isvalid())
def test_intersect02(self): a = DOMRect() b = DOMRect(30, 50, 100, 200) c = a.intersect(b) self.assertTrue(c.isempty()) self.assertTrue(not c.isvalid()) self.assertTrue(a.isempty()) self.assertTrue(not a.isvalid()) self.assertEqual((30, 50, 100, 200), (b.x, b.y, b.width, b.height))
def test_from_rect(self): x = -200 y = -100 width = 600 height = 300 rect = DOMRect.from_rect({'x': x, 'y': y, 'width': width, 'height': height, }) self.assertIsInstance(rect, DOMRect) self.assertFalse(rect.isempty()) self.assertTrue(rect.isvalid()) self.assertEqual(x, rect.x) self.assertEqual(x, rect.left) self.assertEqual(y, rect.y) self.assertEqual(y, rect.top) self.assertEqual(x + width, rect.right) self.assertEqual(y + height, rect.bottom) self.assertEqual(width, rect.width) self.assertEqual(height, rect.height)
def test_eq11(self): a = DOMRect(10, 20, 100, 200) b = DOMRect(10, 20, 105, 205) self.assertNotEqual(b, a)
def test_united_invalid_invalid(self): a = DOMRect() b = DOMRect() c = a.unite(b.x, b.y, b.width, b.height) self.assertTrue(c.isempty()) self.assertTrue(not c.isvalid())
def test_eq01(self): a = DOMRect() b = DOMRect() self.assertEqual(b, a)
def test_eq03(self): a = DOMRect() b = DOMRect(0, 0) self.assertNotEqual(b, a)
def test_eq04(self): a = DOMRect(10, 20) b = DOMRect(10, 20) self.assertEqual(b, a)
def test_eq05(self): a = DOMRect(10, 20, 100, 200) b = DOMRect(10, 20, 100, 200) self.assertEqual(b, a)
def test_intersect01(self): a = DOMRect() b = DOMRect() c = a.intersect(b) self.assertTrue(c.isempty()) self.assertTrue(not c.isvalid())
def test_eq08(self): a = DOMRect(10, 20, 100, 200) b = DOMRect(15, 25, 100, 200) self.assertNotEqual(b, a)