def testissemicompressed(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) ver = SNTVerify(T, [p1, p2, p3, p4]) ver.populate() self.assertTrue(ver.issemicompressed()) n1 = [n for n in ver.uncomplevels[2] if n.point == p3][0] n2 = Node(p3, 1) n2.addch(n1.getchild()) n1.addch(n2) ver.populate() self.assertFalse(ver.issemicompressed()) p1 = Point([-9956], Euclidean()) p2 = Point([1288], Euclidean()) T = SNT(7, 1, 1, 14 / 3) T.setroot(p1) T.insert(p2, T.root) ver = SNTVerify(T, [p1, p2]) ver.populate() self.assertTrue(ver.issemicompressed())
def testupdateonsplit(self): T = SNT(3, 1, 1) T.tau = 2 T.cr = 3 r = Point([0], Euclidean()) T.setroot(r) a = Point([1], Euclidean()) b = Point([8], Euclidean()) c = Point([13], Euclidean()) d = Point([30], Euclidean()) e = Point([63], Euclidean()) f = Point([96], Euclidean()) ploc = SNTPointLocation(T, [a, b, c, d, e, f]) n1 = Node(r, 7) n2 = Node(r, 3) n1.addch(n2) ploc._rnn_in[n1] = {a, b, c, d} ploc._rnn_out[n1] = {e, f} ploc._nn[a] = ploc._nn[b] = ploc._nn[c] = ploc._nn[d] = ploc._nn[ e] = ploc._nn[f] = n1 ploc.updateonsplit(n2) self.assertEqual(ploc._rnn_in[n1], {d}) self.assertEqual(ploc._rnn_out[n1], {e, f}) self.assertEqual(ploc._rnn_in[n2], {a}) self.assertEqual(ploc._rnn_out[n2], {b, c})
def testfinduncomplevels(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) ver = SNTVerify(T, [p1, p2, p3, p4]) ver.finduncomplevels() self.assertEqual(len(ver.uncomplevels), 7) self.assertEqual(next(iter(ver.uncomplevels[5])).point, p1) self.assertEqual(next(iter(ver.uncomplevels[5])).level, 5) self.assertEqual({n.point for n in ver.uncomplevels[4]}, {p1, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[4] if n.level == 4]), 2) self.assertEqual({n.point for n in ver.uncomplevels[3]}, {p1, p3, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[3] if n.level == 3]), 3) self.assertEqual({n.point for n in ver.uncomplevels[2]}, {p1, p3, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[2] if n.level == 2]), 2) self.assertEqual(len([n.level for n in ver.uncomplevels[2] if n.level == 3]), 1) self.assertEqual({n.point for n in ver.uncomplevels[1]}, {p1, p3, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[1] if n.level == 1]), 1) self.assertEqual(len([n.level for n in ver.uncomplevels[1] if n.level == 2]), 1) self.assertEqual(len([n.level for n in ver.uncomplevels[1] if n.level == 3]), 1) self.assertEqual({n.point for n in ver.uncomplevels[0]}, {p1, p2, p3, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[0] if n.level == 0]), 2) self.assertEqual(len([n.level for n in ver.uncomplevels[0] if n.level == 2]), 1) self.assertEqual(len([n.level for n in ver.uncomplevels[0] if n.level == 3]), 1) self.assertEqual({n.point for n in ver.uncomplevels[-1]}, {p1, p2, p3, p4}) self.assertEqual(len([n.level for n in ver.uncomplevels[-1] if n.level == -1]), 2) self.assertEqual(len([n.level for n in ver.uncomplevels[-1] if n.level == 2]), 1) self.assertEqual(len([n.level for n in ver.uncomplevels[-1] if n.level == 3]), 1)
def testsetroot(self): T = SNT(3, 1, 2, 2) rootpoint = Point([1, 2, 3, 4, 5], Euclidean()) T.setroot(rootpoint) self.assertEqual(T.root.point, rootpoint) self.assertEqual(T.root.level, float('inf')) self.assertEqual(T.root.getchild().point, rootpoint) self.assertEqual(T.root.getchild().level, float('-inf'))
def testaddnode(self): T = SNT(5, 1, 1) T.setroot(Point([0], Euclidean())) ploc = SNTPointLocation(T, []) a = Node(Point([1], Euclidean()), 2) ploc.addnode(a) self.assertEqual(ploc._rnn_in[a], set()) self.assertEqual(ploc._rnn_out[a], set())
def testsplitabove(self): T = SNT(4, 1, 1, 2) T.setroot(Point([0], Euclidean())) a = T.splitbelow(T.root, 10) b = T.splitbelow(a, 0) n = T.splitabove(b, 5) self.assertEqual(n.level, 5) self.assertEqual(n.ch, {b}) self.assertEqual(n.par, a) self.assertEqual(b.par, n) self.assertEqual(a.ch, {n})
def testsplitbelow_root(self): T = SNT(3, 1, 1) T.setroot(Point([0], Euclidean())) n = T.splitbelow(T.root, 1) self.assertEqual(n.point, T.root.point) self.assertEqual(n.level, 1) self.assertEqual(n.par, T.root) self.assertEqual(T.root.ch, {n}) self.assertTrue(n in T.root.ch) self.assertEqual(n.getchild().level, float('-inf')) self.assertEqual(n.rel, {n})
def testinit(self): T = SNT(5, 1, 1) T.setroot(Point([0], Euclidean())) points = [Point([i], Euclidean()) for i in [1, 2, 4, 8]] ploc = SNTPointLocation(T, points) for p in points: self.assertEqual(ploc._nn[p], T.root) self.assertEqual(len(ploc._rnn_in), 1) self.assertEqual(len(ploc._rnn_out), 1) self.assertEqual(ploc._rnn_in[T.root], set(points)) self.assertEqual(len(ploc._rnn_out[T.root]), 0)
def testsplitbelow_leaf(self): T = SNT(3, 1, 1) T.setroot(Point([0], Euclidean())) a = T.splitbelow(T.root, 10) n = T.splitbelow(a, 0) self.assertEqual(n.point, a.point) self.assertEqual(n.level, 0) self.assertEqual(n.par, a) self.assertEqual(a.ch, {n}) self.assertTrue(n in a.ch) self.assertTrue(n not in T.root.ch) self.assertEqual(n.getchild().level, float('-inf')) self.assertEqual(n.rel, {n})
def testrelativescorrect(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) ver = SNTVerify(T, [p1, p2, p3, p4]) ver.populate() self.assertTrue(ver.relativescorrect()) [n for n in ver.uncomplevels[2] if n.point == p1][0].rel.discard([n for n in ver.uncomplevels[2] if n.point == p3][0]) self.assertFalse(ver.relativescorrect())
def testinsert_onepointafterroot(self): T = SNT(4, 1, 1, 4) metric = Euclidean() T.setroot(Point([0, 0], metric)) T.insert(Point([6, 0], metric), T.root) # Check root got split below a = next(iter(T.root.ch)) self.assertEqual(a.point, T.root.point) self.assertEqual(a.level, 2) self.assertEqual(len(a.ch), 2) b, c = tuple(child for child in a.ch) self.assertTrue(b.point is not c.point) self.assertEqual(b.level, 1) self.assertEqual(c.level, 1) self.assertEqual(b.getchild().level, float('-inf')) self.assertEqual(c.getchild().level, float('-inf'))
def testrnn(self): T = SNT(3, 1, 1) T.setroot(Point([0], Euclidean())) ploc = SNTPointLocation(T, []) a = Point([1], Euclidean()) b = Point([2], Euclidean()) c = Point([3], Euclidean()) d = Point([4], Euclidean()) n = Node(Point([10], Euclidean()), 3) ploc.addnode(n) ploc._rnn_in[T.root] = {a} ploc._rnn_out[T.root] = {b} ploc._rnn_in[n] = {c} ploc._rnn_out[n] = {d} self.assertEqual(ploc.rnn_in(T.root), {a}) self.assertEqual(ploc.rnn_out(T.root), {b}) self.assertEqual(ploc.rnn_in(n), {c}) self.assertEqual(ploc.rnn_out(n), {d}) self.assertEqual(ploc.rnn_in([T.root, n]), {a, c}) self.assertEqual(ploc.rnn_out([T.root, n]), {b, d}) self.assertEqual(ploc.rnn([T.root, n]), {a, b, c, d})
def testfindminlevelrels(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) ver = SNTVerify(T, [p1, p2, p3, p4]) ver.findminlevelrels() self.assertEqual(ver.minlevels[(p1, p1)], float('-inf')) self.assertEqual(ver.minlevels[(p2, p2)], float('-inf')) self.assertEqual(ver.minlevels[(p3, p3)], float('-inf')) self.assertEqual(ver.minlevels[(p4, p4)], float('-inf')) self.assertEqual(ver.minlevels[(p1, p2)], -1) self.assertEqual(ver.minlevels[(p1, p3)], 2) self.assertEqual(ver.minlevels[(p1, p4)], 3) self.assertEqual(ver.minlevels[(p2, p3)], 2) self.assertEqual(ver.minlevels[(p2, p4)], 3) self.assertEqual(ver.minlevels[(p3, p4)], 3)
def testislocalnettree(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) ver = SNTVerify(T, [p1, p2, p3, p4]) ver.populate() self.assertTrue(ver.islocalnettree()) p3.coords = [8] self.assertFalse(ver.islocalnettree()) p3.coords = [17] self.assertFalse(ver.islocalnettree()) p3.coords = [11] self.assertTrue(ver.islocalnettree()) n1 = [n for n in ver.uncomplevels[3] if n.point == p1][0] n1.point = Point([1], Euclidean()) self.assertFalse(ver.islocalnettree())
def testinsert(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.setroot(p1) T.insert(p2, T.root) T.insert(p3, T.root) T.insert(p4, [ch for ch in T.root.getchild().ch if ch.point == p3][0]) self.assertEqual(T.root.getchild().point, p1) self.assertEqual(T.root.getchild().level, 5) n1 = [ch for ch in T.root.getchild().ch if ch.point == p1][0] n2 = [ch for ch in T.root.getchild().ch if ch.point == p4][0] self.assertTrue(n1.level == n2.level == 4) self.assertEqual(n2.getchild().point, p4) self.assertEqual(n2.getchild().level, 3) self.assertEqual(n2.getchild().getchild().level, float('-inf')) n3 = [ch for ch in n1.ch if ch.point == p1][0] n4 = [ch for ch in n1.ch if ch.point == p3][0] self.assertTrue(n3.level == n4.level == 3) self.assertEqual(n4.getchild().point, p3) self.assertEqual(n4.getchild().level, 2) self.assertEqual(n4.getchild().getchild().level, float('-inf')) self.assertEqual(n3.getchild().point, p1) self.assertEqual(n3.getchild().level, 2) self.assertEqual(n3.getchild().getchild().point, p1) self.assertEqual(n3.getchild().getchild().level, 1) n5 = [ch for ch in n3.getchild().getchild().ch if ch.point == p1][0] n6 = [ch for ch in n3.getchild().getchild().ch if ch.point == p2][0] self.assertTrue(n5.level == n6.level == 0) self.assertEqual(n5.getchild().point, p1) self.assertEqual(n5.getchild().level, -1) self.assertEqual(n6.getchild().point, p2) self.assertEqual(n6.getchild().level, -1) self.assertEqual(n5.getchild().getchild().level, float('-inf')) self.assertEqual(n6.getchild().getchild().level, float('-inf'))