def testconstruct(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) T.construct([p2, p3, p4, p1], PL) 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'))
def testall(self): points = [Point([x, 0, 1], Euclidean()) for x in [2, 11, 28, 0]] T = SNT(2, 1, 1, 4) T.construct(points, SNTPointLocation) stats = SNTStats(T) self.assertEqual(stats.levelno(), 6) self.assertEqual(stats.nodeno(), 12) self.assertEqual(stats.childno(), 12) self.assertEqual(stats.relno(), 26) self.assertEqual(stats.jumpno(), 0) points = [Point([x], Euclidean()) for x in [25, 20, 54, 30, 40, 0]] T = SNT(5, 1, 1) T.construct(points, SNTPointLocation) stats = SNTStats(T) self.assertEqual(stats.levelno(), 3) self.assertEqual(stats.nodeno(), 10) self.assertEqual(stats.childno(), 10) self.assertEqual(stats.relno(), 30) self.assertEqual(stats.jumpno(), 0) points = [Point([x, 0, 1], Euclidean()) for x in [2, 65, 69, 0]] T = SNT(2, 1, 1, 4) T.construct(points, SNTPointLocation) stats = SNTStats(T) self.assertEqual(stats.jumpno(), 2)
def testconstructwithverification(self): points = [ Point([x, 0, 1], Euclidean()) for x in [8, 1, 2, 32, 64, 81, 80, 160] ] T = SNT(4, 1, 1, 4) T.construct(points, PL) ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.issemicompressed()) self.assertTrue(ver.islocalnettree()) self.assertFalse(ver.isglobalnettree()) T.cc = 4 / 3 T.cp = 1 / 6 self.assertTrue(ver.isglobalnettree()) points = [Point([x], Euclidean()) for x in [7, 44, 30, 24, 76]] T = SNT(5, 1, 1) T.construct(points, PL) ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.issemicompressed()) self.assertTrue(ver.islocalnettree()) T.cc = 5 / 4 T.cp = 1 / 4 self.assertTrue(ver.isglobalnettree()) points = [Point([x], Euclidean()) for x in [25, 20, 54, 30, 40, 0]] T = SNT(5, 1, 1) T.construct(points, PL) ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.issemicompressed()) self.assertTrue(ver.islocalnettree()) T.cc = 5 / 4 T.cp = 1 / 4 self.assertTrue(ver.isglobalnettree()) points = [ Point([x], Euclidean()) for x in [-55, 93, -90, -14, -13, -12] ] T = SNT(7, 1, 1) T.construct(points, PL) ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.islocalnettree()) self.assertTrue(ver.issemicompressed()) metric = Euclidean() points = [ Point([random.randint(-10000, 10000) for _ in range(2)], metric) for _ in range(200) ] tmp = list() for p in points: if p in tmp: print('duplicate:', p) else: tmp.append(p) points = tmp tau = 7 T = SNT(tau, 1, 1) T.construct(points, PL) ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.islocalnettree()) self.assertTrue(ver.issemicompressed()) T.cc = tau / (tau - 1) T.cp = (tau - 3) / (2 * (tau - 1)) self.assertTrue(ver.isglobalnettree())