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 testconstruct(self): T = SNT(2, 1, 1, 4) p1 = Point([0], Euclidean()) p2 = Point([2], Euclidean()) p3 = Point([11], Euclidean()) p4 = Point([28], Euclidean()) print(T.construct([p2, p3, p4, p1], None)) points = [p1, p2, p3, p4] ver = SNTVerify(T, points) ver.populate() self.assertTrue(ver.relativescorrect()) self.assertTrue(ver.issemicompressed()) self.assertTrue(ver.islocalnettree())
def testrandom(self): metric = Euclidean() points = [Point([random.randint(-10000, 10000) for _ in range(3)], metric) for _ in range(2000)] tmp = list() for p in points: if p in tmp: print('duplicate:', p) else: tmp.append(p) points = tmp tau = 5 T = SNT(tau, 1, 1) print(T.construct(points, None)) 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())
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())