|
|
|
import pytest
|
|
|
|
|
|
|
|
from clusterview.points import Attribute, Point, PointSet
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty():
|
|
|
|
l = PointSet(3, 100, 100)
|
|
|
|
|
|
|
|
assert l.empty()
|
|
|
|
|
|
|
|
def test_add_to_point_set():
|
|
|
|
l = PointSet(3, 100, 100)
|
|
|
|
|
|
|
|
l.add_point(1, 2)
|
|
|
|
|
|
|
|
points = list(l.points)
|
|
|
|
|
|
|
|
p = Point(1, 2, 3, 100, 100)
|
|
|
|
assert len(points) == 1
|
|
|
|
assert points[0] == p
|
|
|
|
assert len(l.attributes(p)) == 0
|
|
|
|
|
|
|
|
def test_add_to_point_set_with_attributes():
|
|
|
|
attribute = Attribute("thing", 1)
|
|
|
|
|
|
|
|
l = PointSet(3, 100, 100)
|
|
|
|
l.add_point(2, 3, attrs=[attribute])
|
|
|
|
|
|
|
|
points = list(l.points)
|
|
|
|
point = Point(2, 3, 3, 100, 100)
|
|
|
|
attrs = l.attributes(point)
|
|
|
|
|
|
|
|
assert len(points) == 1
|
|
|
|
assert points[0] == point
|
|
|
|
assert len(l.attributes(point)) == 1
|
|
|
|
|
|
|
|
def test_remove_point_exact_click():
|
|
|
|
attribute = Attribute("thing", 1)
|
|
|
|
|
|
|
|
l = PointSet(8, 100, 100)
|
|
|
|
l.add_point(4, 4, attrs=[attribute])
|
|
|
|
|
|
|
|
p = Point(4, 4, 8, 100, 100)
|
|
|
|
l.remove_point(4, 4)
|
|
|
|
|
|
|
|
points = list(l.points)
|
|
|
|
|
|
|
|
assert len(points) == 0
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
# We expect a call to attributes on a removed
|
|
|
|
# point to raise a KeyError because it no
|
|
|
|
# longer exists in the point -> attribute_list
|
|
|
|
# dictionary.
|
|
|
|
l.attributes(p)
|
|
|
|
|
|
|
|
def test_remove_point_bounding_box():
|
|
|
|
"""
|
|
|
|
This test checks the bounding box hit heuristic.
|
|
|
|
"""
|
|
|
|
attribute = Attribute("thing", 1)
|
|
|
|
|
|
|
|
l = PointSet(8, 100, 100)
|
|
|
|
l.add_point(4, 4, attrs=[attribute])
|
|
|
|
|
|
|
|
p = Point(4, 4, 8, 100, 100)
|
|
|
|
|
|
|
|
# The click-point (2, 1) will be inside of our point size 8
|
|
|
|
# bounding box.
|
|
|
|
l.remove_point(4, 4)
|
|
|
|
|
|
|
|
points = list(l.points)
|
|
|
|
|
|
|
|
assert len(points) == 0
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
# We expect a call to attributes on a removed
|
|
|
|
# point to raise a KeyError because it no
|
|
|
|
# longer exists in the point -> attribute_list
|
|
|
|
# dictionary.
|
|
|
|
l.attributes(p)
|
|
|
|
|
|
|
|
def test_attributes_must_be_array_of_attributes():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
l = PointSet(8, 100, 100)
|
|
|
|
l.add_point(4, 4, attrs=[1,2,3,4,5])
|
|
|
|
|
|
|
|
def test_clear_all_selected_points():
|
|
|
|
l = PointSet(8, 100, 100)
|
|
|
|
l.add_point(4, 4)
|
|
|
|
l.add_point(5, 5)
|
|
|
|
|
|
|
|
for p in l.points:
|
|
|
|
p.select()
|
|
|
|
|
|
|
|
selected = 0
|
|
|
|
|
|
|
|
for p in l.points:
|
|
|
|
if p.selected:
|
|
|
|
selected += 1
|
|
|
|
|
|
|
|
assert selected == 2
|
|
|
|
|
|
|
|
l.clear_selection()
|
|
|
|
|
|
|
|
unselected = 0
|
|
|
|
|
|
|
|
for p in l.points:
|
|
|
|
if not p.selected:
|
|
|
|
unselected += 1
|
|
|
|
|
|
|
|
assert unselected == 2
|