Ejemplo n.º 1
0
 def setUp(self):
     self.band = FrequencyBand()
Ejemplo n.º 2
0
class TestFreqBand(unittest.TestCase):
    def setUp(self):
        self.band = FrequencyBand()

    def test_deallocation(self):
        self.band.allocate_pos(0)
        self.assertTrue(self.band.state == 1)
        self.band.deallocate_pos(0)
        self.assertTrue(self.band.state == 0)

        self.band.allocate_pos(0)
        self.band.allocate_pos(1)
        self.assertTrue(self.band.state == 3)
        self.band.deallocate_pos(1)
        self.assertTrue(self.band.state == 1)

    def test_interference(self):
        """
        Check that the interference evaluation is correct by using
        the example provided.
        """
        for pos in (0, 1, 4, 6):
            self.band.allocate_pos(pos)

        interference = 1

        for x, y in ((3, 1), (7, 5), (7, 5), (5, 3)):
            interference *= float(x) / float(y)

        interference = math.log(interference)

        self.assertTrue(self.band.interference_at(3) == interference)

    def test_saturate(self):
        ret = [self.band.allocate_center() for i in range(32)]
        ret.sort()

        self.assertTrue(ret == range(32))

    def test_center(self):
        delta = 0

        for _ in range(16):
            self.assertTrue(self.band.allocate_center() == 16 + delta)
            delta += 1
            self.assertTrue(self.band.allocate_center() == 16 - delta)

        self.assertTrue(self.band.allocate_center() is None)

    def test_side(self):
        left, right = 0, 31

        for _ in range(16):
            self.assertTrue(self.band.allocate_side() == left)
            self.assertTrue(self.band.allocate_side() == right)

            left += 1
            right -= 1

    def test_complete(self):
        for _ in range(16):
            self.assertTrue(self.band.allocate_center() is not None)
            self.assertTrue(self.band.allocate_side() is not None)

        self.assertTrue(self.band.allocate_side() is None)
        self.assertTrue(self.band.allocate_center() is None)