Exemple #1
0
 def testisglobalnettree(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.isglobalnettree())
     p2.coords = [9]
     self.assertFalse(ver.isglobalnettree())
     p2.coords = [2]
     p3.coords = [10]
     self.assertFalse(ver.isglobalnettree())
     p3.coords = [11]
     self.assertTrue(ver.isglobalnettree())
     n1 = [n for n in ver.uncomplevels[3] if n.point == p1][0]
     n1.point = Point([1], Euclidean())
     self.assertFalse(ver.isglobalnettree())
Exemple #2
0
 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())
Exemple #3
0
    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())