def test_suid_from_index(self):
     for rdggs in [WGS84_123, WGS84_123_RADIANS]:
         # Test order='level'.
         # The suid with index 0 should be N.
         suid = (N,)
         get = Cell.suid_from_index(rdggs, 0, order='level')
         self.assertEqual(get, suid)
     
         # Should be correct on cell P1.
         suid = (P, 1)
         i = 25
         get = Cell.suid_from_index(rdggs, i, order='level')
         self.assertEqual(get, suid)
     
         # Test order='post'.
         # The suid with index 0 should be N00...0.
         suid = [N] + [0 for i in range(rdggs.max_resolution)]
         suid = tuple(suid)
         get = Cell.suid_from_index(rdggs, 0, order='post')
         self.assertEqual(get, suid)
     
         # Should be correct on cell P1.
         suid = (P, 1)
         def num(k):
             return WGS84_123.num_cells(res_1=k, subcells=True)
         i = 2 * num(0) + 1 * num(1) + num(1) - 1
         get = Cell.suid_from_index(rdggs, i, order='post')
         self.assertEqual(get, suid)
Exemplo n.º 2
0
    def test_suid_from_index(self):
        for rdggs in [WGS84_123, WGS84_123_RADIANS]:
            # Test order='level'.
            # The suid with index 0 should be N.
            suid = (N, )
            get = Cell.suid_from_index(rdggs, 0, order='level')
            self.assertEqual(get, suid)

            # Should be correct on cell P1.
            suid = (P, 1)
            i = 25
            get = Cell.suid_from_index(rdggs, i, order='level')
            self.assertEqual(get, suid)

            # Test order='post'.
            # The suid with index 0 should be N00...0.
            suid = [N] + [0 for i in range(rdggs.max_resolution)]
            suid = tuple(suid)
            get = Cell.suid_from_index(rdggs, 0, order='post')
            self.assertEqual(get, suid)

            # Should be correct on cell P1.
            suid = (P, 1)

            def num(k):
                return WGS84_123.num_cells(res_1=k, subcells=True)

            i = 2 * num(0) + 1 * num(1) + num(1) - 1
            get = Cell.suid_from_index(rdggs, i, order='post')
            self.assertEqual(get, suid)
    def test_index(self):
        for rdggs in [WGS84_123, WGS84_123_RADIANS]:
            # Empty cell should have index None
            empty = rdggs.cell()
            self.assertEqual(empty.index(order='level'), None)
            self.assertEqual(empty.index(order='post'), None)

            # Test order='level'.
            # A cell should have index one greater than its predecessor
            # at the same resolution.
            c = rdggs.cell((N, 2, 7, 4, 8))
            b = c.predecessor()
            self.assertEqual(c.index(order='level'), 
                             b.index(order='level') + 1)
        
            # It should invert suid_from_index().
            M = rdggs.num_cells(0, rdggs.max_resolution)
            k = 3616048 #randint(0, M - 1)
            get = Cell(rdggs, 
                  Cell.suid_from_index(rdggs, k, order='level')).\
                  index(order='level')
            self.assertEqual(get, k)

            # Test order='post'.
            # The cell N00...0 should have index 0.
            suid = [N] + [0]*rdggs.max_resolution
            a = Cell(rdggs, suid)
            self.assertEqual(a.index(order='post'), 0)
        
            # A cell should have index one greater than its last child.
            cc = list(c.subcells())[8]
            self.assertEqual(c.index(order='post'),       
                             cc.index(order='post') + 1)
        
            # It should invert suid_from_index().
            k = 3616048 #randint(0, M - 1)
            get = Cell(rdggs, 
                       Cell.suid_from_index(rdggs, k, order='post')).\
                       index(order='post')
            self.assertEqual(get, k)
Exemplo n.º 4
0
    def test_index(self):
        for rdggs in [WGS84_123, WGS84_123_RADIANS]:
            # Empty cell should have index None
            empty = rdggs.cell()
            self.assertEqual(empty.index(order='level'), None)
            self.assertEqual(empty.index(order='post'), None)

            # Test order='level'.
            # A cell should have index one greater than its predecessor
            # at the same resolution.
            c = rdggs.cell((N, 2, 7, 4, 8))
            b = c.predecessor()
            self.assertEqual(c.index(order='level'),
                             b.index(order='level') + 1)

            # It should invert suid_from_index().
            M = rdggs.num_cells(0, rdggs.max_resolution)
            k = 3616048  #randint(0, M - 1)
            get = Cell(rdggs,
                  Cell.suid_from_index(rdggs, k, order='level')).\
                  index(order='level')
            self.assertEqual(get, k)

            # Test order='post'.
            # The cell N00...0 should have index 0.
            suid = [N] + [0] * rdggs.max_resolution
            a = Cell(rdggs, suid)
            self.assertEqual(a.index(order='post'), 0)

            # A cell should have index one greater than its last child.
            cc = list(c.subcells())[8]
            self.assertEqual(c.index(order='post'), cc.index(order='post') + 1)

            # It should invert suid_from_index().
            k = 3616048  #randint(0, M - 1)
            get = Cell(rdggs,
                       Cell.suid_from_index(rdggs, k, order='post')).\
                       index(order='post')
            self.assertEqual(get, k)