# 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
        # Multiple range freelist. Reserve overlapping range

        flist, unfreed = freelist.unfree_range(self.flist2, 5, 12)
        self.assertEqual(flist, self.flist2)
        self.assertEqual(unfreed, None)

        # Multiple range freelist. Reserve non-overlapping range

        flist, unfreed = freelist.unfree_range(self.flist2, 26, 38)
        self.assertEqual(flist, [{'start': 10, 'end': 18},
                                 {'start': 20, 'end': 25},
                                 {'start': 39, 'end': 254}])
        self.assertEqual(unfreed, [26, 38])

        # Single element freelist. Reserve that element

        flist, unfreed = freelist.unfree_range(self.flist3, 254)
        self.assertEqual(flist, [])
        self.assertEqual(unfreed, 254)

        # Single element freelist. Reserve out of bounds range

        flist, unfreed = freelist.unfree_range(self.flist3, 5, 12)
        self.assertEqual(flist, self.flist3)
        self.assertEqual(unfreed, None)

    def test_free_range(self):

        # Empty freelist. Free range


# 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

        # Multiple range freelist. Reserve overlapping range

        flist, unfreed = freelist.unfree_range(self.flist2, 5, 12)
        self.assertEqual(flist, self.flist2)
        self.assertEqual(unfreed, None)

        # Multiple range freelist. Reserve non-overlapping range

        flist, unfreed = freelist.unfree_range(self.flist2, 26, 38)
        self.assertEqual(flist, [{'start': 10, 'end': 18},
                                 {'start': 20, 'end': 25},
                                 {'start': 39, 'end': 254}])
        self.assertEqual(unfreed, [26, 38])

        # Single element freelist. Reserve that element

        flist, unfreed = freelist.unfree_range(self.flist3, 254)
        self.assertEqual(flist, [])
        self.assertEqual(unfreed, 254)

        # Single element freelist. Reserve out of bounds range

        flist, unfreed = freelist.unfree_range(self.flist3, 5, 12)
        self.assertEqual(flist, self.flist3)
        self.assertEqual(unfreed, None)

    def test_free_range(self):

        # Empty freelist. Free range


        flist, freed = freelist.free_range(self.flist0, 6, 8)