You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.5 KiB
114 lines
2.5 KiB
import pytest |
|
|
|
from clusterview.colors import Color |
|
from clusterview.points import Attribute, Point, PointSet |
|
|
|
|
|
def test_empty(): |
|
point_set = PointSet(3, 100, 100) |
|
|
|
assert point_set.empty() |
|
|
|
|
|
def test_add_to_point_set(): |
|
point_set = PointSet(3, 100, 100) |
|
|
|
point_set.add_point(1, 2, Color.GREY) |
|
|
|
points = list(point_set.points) |
|
|
|
p = Point(1, 2, Color.GREY, 3, 100, 100) |
|
assert len(points) == 1 |
|
assert points[0] == p |
|
|
|
|
|
def test_add_to_point_set_with_attributes(): |
|
attribute = Attribute("thing", 1) |
|
|
|
point_set = PointSet(3, 100, 100) |
|
point_set.add_point(2, 3, Color.GREY, attrs=[attribute]) |
|
|
|
points = list(point_set.points) |
|
|
|
assert len(points) == 1 |
|
assert len(points[0].attributes) == 1 |
|
|
|
|
|
def test_remove_point_exact_click(): |
|
attribute = Attribute("thing", 1) |
|
|
|
point_set = PointSet(8, 100, 100) |
|
point_set.add_point(4, 4, Color.GREY, attrs=[attribute]) |
|
|
|
point_set.remove_point(4, 4) |
|
|
|
points = list(point_set.points) |
|
|
|
assert len(points) == 0 |
|
|
|
|
|
def test_remove_point_bounding_box(): |
|
""" |
|
This test checks the bounding box hit heuristic. |
|
""" |
|
attribute = Attribute("thing", 1) |
|
|
|
point_set = PointSet(8, 100, 100) |
|
point_set.add_point(4, 4, Color.GREY, attrs=[attribute]) |
|
|
|
# The click-point (2, 1) will be inside of our point size 8 |
|
# bounding box. |
|
point_set.remove_point(4, 4) |
|
|
|
points = list(point_set.points) |
|
|
|
assert len(points) == 0 |
|
|
|
|
|
def test_clear_all_selected_points(): |
|
point_set = PointSet(8, 100, 100) |
|
point_set.add_point(4, 4, Color.GREY) |
|
point_set.add_point(5, 5, Color.GREY) |
|
|
|
for p in point_set.points: |
|
p.select() |
|
|
|
selected = 0 |
|
|
|
for p in point_set.points: |
|
if p.selected: |
|
selected += 1 |
|
|
|
assert selected == 2 |
|
|
|
point_set.clear_selection() |
|
|
|
unselected = 0 |
|
|
|
for p in point_set.points: |
|
if not p.selected: |
|
unselected += 1 |
|
|
|
assert unselected == 2 |
|
|
|
|
|
def test_groups(): |
|
point_set = PointSet(8, 100, 100) |
|
point_set.add_point(4, 4, Color.GREY) |
|
point_set.add_point(5, 5, Color.GREY) |
|
point_set.add_point(10, 4, Color.BLUE) |
|
point_set.add_point(30, 5, Color.BLUE) |
|
|
|
p1 = Point(4, 4, Color.GREY, 8, 100, 100) |
|
p2 = Point(5, 5, Color.GREY, 8, 100, 100) |
|
p3 = Point(10, 4, Color.BLUE, 8, 100, 100) |
|
p4 = Point(30, 5, Color.BLUE, 8, 100, 100) |
|
|
|
expected = { |
|
Color.GREY: [p1, p2], |
|
Color.BLUE: [p3, p4] |
|
} |
|
|
|
groups = point_set.groups() |
|
|
|
assert groups == expected
|
|
|