Exemple #1
0
 def testfindleaves(self):
     T = SNT(3, 1, 1)
     T.root = Node(Point([0], Euclidean()), float('inf'))
     n1 = Node(Point([1], Euclidean()), 3)
     n2 = Node(Point([2], Euclidean()), 3)
     n3 = Node(Point([3], Euclidean()), 2)
     n4 = Node(Point([4], Euclidean()), 2)
     n5 = Node(Point([5], Euclidean()), 1)
     n6 = Node(Point([6], Euclidean()), 1)
     T.root.addch(n1)
     T.root.addch(n2)
     n1.addch(n3)
     n1.addch(n4)
     n4.addch(n5)
     n4.addch(n6)
     ver = SNTVerify(T, [])
     dic = dict()
     ver.findleaves(T.root, dic)
     self.assertEqual(dic[T.root], {n2, n3, n5, n6})
     self.assertEqual(dic[n1], {n3, n5, n6})
     self.assertEqual(dic[n2], {n2})
     self.assertEqual(dic[n3], {n3})
     self.assertEqual(dic[n4], {n5, n6})
     self.assertEqual(dic[n5], {n5})
     self.assertEqual(dic[n6], {n6})
 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)
Exemple #3
0
 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)
Exemple #4
0
 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())
Exemple #5
0
 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())
Exemple #6
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())
 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())
Exemple #8
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())
Exemple #9
0
    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())