示例#1
0
def test_div():
    c = Coord(*xy) / 4
    assert isinstance(c, Coord)
    assert c == (0.25, 0.5)
    c = Coord(*xy)
    c /= 4
    assert isinstance(c, Coord)
    assert c == (0.25, 0.5)
示例#2
0
def test_mul():
    c = Coord(*xy) * 4
    assert isinstance(c, Coord)
    assert c == (4, 8)
    c = 4 * Coord(*xy)
    assert isinstance(c, Coord)
    assert c == (4, 8)
    c = Coord(*xy)
    c *= 4
    assert isinstance(c, Coord)
    assert c == (4, 8)
示例#3
0
def test_sub():
    c = Coord(*xy) - (2, 3)
    assert isinstance(c, Coord)
    assert c == (-1, -1)
    c = (2, 3) - Coord(*xy)
    assert isinstance(c, Coord)
    assert c == (1, 1)
    c = Coord(*xy)
    c -= (2, 3)
    assert isinstance(c, Coord)
    assert c == (-1, -1)
示例#4
0
def test_add():
    c = Coord(*xy) + (2, 3)
    assert isinstance(c, Coord)
    assert c == (3, 5)
    c = (2, 3) + Coord(*xy)
    assert isinstance(c, Coord)
    assert c == (3, 5)
    c = Coord(*xy)
    c += (2, 3)
    assert isinstance(c, Coord)
    assert c == (3, 5)
示例#5
0
def test_eq():
    assert Coord(*xy) == xy
    assert xy == Coord(*xy)
    assert Coord(*xy) == Coord(*xy)
    assert Coord(*xy) != ab
    assert ab != Coord(*xy)
    assert Coord(*xy) != Coord(*ab)
示例#6
0
def test_attr_set():
    c = Coord(*xy)
    c.xy = ab
    assert c == ab

    c = Coord(*xy)
    assert c == Coord(*xy)
    c.x = a
    c.y = b
    assert c == ab
示例#7
0
def test_iter():
    assert tuple(Coord(*xy)) == xy
示例#8
0
def test_index_set():
    c = Coord(*xy)
    c[0] = a
    c[1] = b
    c == ab
示例#9
0
def test_len():
    assert len(Coord(*xy)) == 2
示例#10
0
def test_index_get():
    assert Coord(*xy)[0] == x
    assert Coord(*xy)[1] == y
示例#11
0
def test_attr_get():
    c = Coord(*xy)
    assert c.x == x
    assert c.y == y
    assert c.xy == xy
示例#12
0
def test_init():
    assert Coord(x, y) == xy
    assert Coord(*xy) == xy
示例#13
0
def test_str():
    assert str(Coord(*xy)) == "(1, 2)"
    assert repr(Coord(*xy)) == "<Coord(1, 2)>"
示例#14
0
 def mouse_handler(self, e: Any):
     if e.type in (pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP,
                   pygame.MOUSEBUTTONDOWN):
         e.pos = tuple(Coord(*e.pos) / self.scale)