# Path: luna/utils/freelist.py
# def next_free(flist):
# def unfree_range(flist, start, end=None):
# def free_range(flist, start, end=None):
# def set_upper_limit(flist, end, prev_end):
# def get_nonfree(flist, limit=None):


import mock
import unittest
import os
from luna.utils import freelist

        # Simple freelist. free last element

        flist, freed = freelist.free_range(self.flist1, 255)
        self.assertEqual(flist, [{'start': 1, 'end': 255}])
        self.assertEqual(freed, 255)

        # Simple freelist. free first element

        flist, freed = freelist.free_range(self.flist1, 0)
        self.assertEqual(flist, [{'start': 0, 'end': 254}])
        self.assertEqual(freed, 0)

        # Multiple range freelist. Free overlapping range

        flist, freed = freelist.free_range(self.flist2, 15, 19)
        self.assertEqual(flist, [{'start': 10, 'end': 254}])
        self.assertEqual(freed, [15, 19])

        # Multiple range freelist. Free non-overlapping range

        flist, freed = freelist.free_range(self.flist2, 4, 8)
        self.assertEqual(flist, [{'start': 4, 'end': 8},
                                 {'start': 10, 'end': 18},
                                 {'start': 20, 'end': 254}])
        self.assertEqual(freed, [4, 8])

        # Single element freelist. Free other range

        flist, freed = freelist.free_range(self.flist3, 5, 12)

# Path: luna/utils/freelist.py
# def next_free(flist):
# def unfree_range(flist, start, end=None):
# def free_range(flist, start, end=None):
# def set_upper_limit(flist, end, prev_end):
# def get_nonfree(flist, limit=None):


# Path: tests/unittests/test_utils_freelist.py
import mock
import unittest
import os
from luna.utils import freelist


        # Simple freelist. free last element

        flist, freed = freelist.free_range(self.flist1, 255)
        self.assertEqual(flist, [{'start': 1, 'end': 255}])
        self.assertEqual(freed, 255)

        # Simple freelist. free first element

        flist, freed = freelist.free_range(self.flist1, 0)
        self.assertEqual(flist, [{'start': 0, 'end': 254}])
        self.assertEqual(freed, 0)

        # Multiple range freelist. Free overlapping range

        flist, freed = freelist.free_range(self.flist2, 15, 19)
        self.assertEqual(flist, [{'start': 10, 'end': 254}])
        self.assertEqual(freed, [15, 19])

        # Multiple range freelist. Free non-overlapping range

        flist, freed = freelist.free_range(self.flist2, 4, 8)
        self.assertEqual(flist, [{'start': 4, 'end': 8},
                                 {'start': 10, 'end': 18},
                                 {'start': 20, 'end': 254}])
        self.assertEqual(freed, [4, 8])

        # Single element freelist. Free other range

        flist, freed = freelist.free_range(self.flist3, 5, 12)

        self.assertEqual(flist, [{'start': 5, 'end': 12},