import unittest from nose.tools import eq_ from helix.helpers.nodequadtree import Bounds, NodeQuadTree from helix.models.coordinate import Coordinate class DummyNode: def __init__(self, x, y): self.coordinate = Coordinate(x, y) class NodeQuadTreeTest(unittest.TestCase): def setUp(self): self.quadTree = NodeQuadTree(1, Bounds(0, 100, 0, 100), 0.5) def test_lower_leaves(self): nodes = [ DummyNode(1, 1), DummyNode(4, 1), DummyNode(6, 1), DummyNode(9, 1), DummyNode(1, 9), DummyNode(4, 9), DummyNode(6, 9), DummyNode(9, 9) ] for i in range(100): for n in nodes: self.quadTree.insert(n) output = [] self.quadTree.report(output) expected = [0, 0, 0, 0, 200, 200, 200, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0] eq_(output, expected) def test_top_level_degenerate(self): nodes = [] for i in range(0, 100): nodes.append(DummyNode(50, i)) nodes.append(DummyNode(i, 50)) for n in nodes: self.quadTree.insert(n) output = [] self.quadTree.report(output) expected = [200, 0, 0, 0, 0] eq_(output, expected) def test_every_point(self): nodes = [] for x in range(0, 100): for y in range(0, 100): nodes.append(DummyNode(x, y)) for n in nodes: self.quadTree.insert(n) output = [] self.quadTree.report(output) expected = [199, 0, 49, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 49, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 49, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 49, 23, 36, 30, 30, 25, 23, 36, 30, 30, 25, 23, 36, 30, 30, 25, 23, 36, 30, 30, 25, 0, 49, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 48, 23, 30, 25, 36, 30, 22, 30, 20, 36, 24, 23, 30, 25, 36, 30, 22, 30, 20, 36, 24, 49, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 48, 23, 36, 30, 30, 25, 22, 36, 24, 30, 20, 23, 36, 30, 30, 25, 22, 36, 24, 30, 20, 0, 49, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 49, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 23, 30, 25, 36, 30, 48, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 22, 30, 36, 20, 24, 22, 30, 36, 20, 24, 48, 23, 36, 30, 30, 25, 23, 36, 30, 30, 25, 22, 36, 30, 24, 20, 22, 36, 30, 24, 20, 0, 49, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 23, 25, 30, 30, 36, 48, 23, 30, 25, 36, 30, 22, 30, 20, 36, 24, 23, 30, 25, 36, 30, 22, 30, 20, 36, 24, 48, 23, 30, 36, 25, 30, 23, 30, 36, 25, 30, 22, 30, 36, 20, 24, 22, 30, 36, 20, 24, 47, 23, 36, 30, 30, 25, 22, 36, 24, 30, 20, 22, 36, 30, 24, 20, 21, 36, 24, 24, 16] eq_(output, expected)