Example #1
0
    def test_insertion(self):
        "test insertions"

        len_max = 4
        l = sorted_points_list_limited(self.normal_list, len_max=len_max)

        # inserting more important point
        p = {'importance': 1234567}
        l.insert(p)
        self.assertEqual(len(l), len_max)
        self.assertTrue(p in l)

        # inserting non-important point
        p = {'importance': 1}
        l.insert(p)
        self.assertEqual(len(l), len_max)
        self.assertFalse(p in l)

        # test that returns True if inserts and False otherwise
        l = sorted_points_list_limited(self.normal_list, len_max=len_max)
        p = {'importance': 1234567}
        self.assertTrue(l.insert(p))

        p = {'importance': 1}
        self.assertFalse(l.insert(p))
Example #2
0
    def test_insertion(self):
        "test insertions"

        len_max = 4
        l = sorted_points_list_limited(self.normal_list,len_max = len_max)

        # inserting more important point
        p = {'importance':1234567}
        l.insert(p)
        self.assertEqual(len(l),len_max)
        self.assertTrue(p in l)

        # inserting non-important point
        p = {'importance':1}
        l.insert(p)
        self.assertEqual(len(l),len_max)
        self.assertFalse(p in l)
    
        # test that returns True if inserts and False otherwise
        l = sorted_points_list_limited(self.normal_list,len_max = len_max)
        p = {'importance':1234567}
        self.assertTrue(l.insert(p))
    
        p = {'importance':1}
        self.assertFalse(l.insert(p))
Example #3
0
    def test_initialization(self):
        """test that sorted list is initialized
        """

        l = sorted_points_list_limited(self.normal_list)

        # points with larger importance are earlier
        zs = [x['importance'] for x in l]
        for i in range(len(zs) - 1):
            self.assertTrue(zs[i] >= zs[i + 1])

        #test that maximum length is not exceeded during initialization
        len_max = 4
        l = sorted_points_list_limited(self.normal_list, len_max=len_max)
        self.assertEqual(len(l), len_max)
Example #4
0
    def test_initialization(self):
        """test that sorted list is initialized
        """
       
        l = sorted_points_list_limited(self.normal_list)

        # points with larger importance are earlier
        zs = [x['importance'] for x in l]
        for i in range(len(zs)-1):
            self.assertTrue(zs[i]>=zs[i+1])

        #test that maximum length is not exceeded during initialization
        len_max = 4
        l = sorted_points_list_limited(self.normal_list,len_max = len_max)
        self.assertEqual(len(l),len_max)
Example #5
0
    def update_tile(tile_key_name, children_updated_list, gt_key_name=None):
        """Updates a single tile, returns Tile model corresponding to tile_str. Datastore is not updated."""
        if not gt_key_name:
            gt_key_name = GeoTree._GEO_TREE_KEY
        t = Tile.get_by_key_name(tile_key_name)
        if not t:
            x,y,z = tile_str_to_tuple(tile_key_name)
            t = Tile(x=x, y=y, z=z, gt_key_name=gt_key_name, key_name=tile_key_name)
        points = sorted_points_list_limited([])
        for child_tile_key_name in children_updated_list:
            ct = Tile.get_by_key_name(child_tile_key_name)
            if ct:
                # in order insert points from child tile to parent
                # stop when does not insert any more

                # TODO: refactor to a single function
                # from native points
                if ct.points_native:
                    for p in json.loads(ct.points_native):
                        if not points.insert(p):
                            break

                # from points
                if ct.points:
                    for p in json.loads(ct.points):
                        if not points.insert(p):
                            break

                t.points = (json.dumps(points))

        return t