コード例 #1
0
    def test_port_costs(self):
        p = OutputPort('SW2')
        p2 = OutputPort('ES2')

        M = np.array([[0, 10, 100], [10, 20, 100]])

        M2 = np.array([[0, 10, 100], [10, 50, 100]])

        p._M_Windows = M
        p2._M_Windows = M2

        s1 = Switch('SW1')
        s2 = Switch('SW2')

        s1.output_ports = {'SW2': p}
        s2.output_ports = {'ES2': p2}

        tc = TC({'SW1': s1, 'SW2': s2}, {}, '')

        cc = cost_check.CostChecker()
        self.assertEqual(cc.cost(tc), 20 / 100 + 50 / 100)

        d = cc.port_costs(tc)
        self.assertEqual(True, d['SW1,SW2'] == 20 / 100)
        self.assertEqual(True, d['SW2,ES2'] == 50 / 100)
コード例 #2
0
    def test_same_period_empty_but_period(self):
        p = OutputPort('SW1')

        M = np.array([[0, 0, 100], [0, 0, 100]])

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 0 / 100)
コード例 #3
0
    def test_same_period_overlap(self):
        p = OutputPort('SW1')

        M = np.array([[0, 20, 100], [10, 20, 100]])

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 20 / 100)
コード例 #4
0
    def test_different_period_overlap(self):
        p = OutputPort('SW1')

        M = np.array([[0, 10, 50], [0, 10, 65]])

        p._M_Windows = M

        self.assertEqual(p.get_occupation_percentage(), 210 / 650)
コード例 #5
0
    def test_dq_period_unevenstart(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 1337

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 668)
コード例 #6
0
    def test_empty_windows(self):
        p = OutputPort('SW1')

        M = np.array([[0, 0, 0], [0, 0, 0]])

        p._M_Windows = M

        with self.assertRaises(ValueError) as e:
            p.get_occupation_percentage()
コード例 #7
0
    def test_dq_period_normal(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 100

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 50)
        p.dq_modify_period(False)
        self.assertEqual(p._free_period, 75)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 62)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 56)
        p.dq_modify_period(False)
        self.assertEqual(p._free_period, 59)
        self.assertEqual(p.dq_modify_period(True), True)
コード例 #8
0
    def test_port_costs(self):
        p = OutputPort('SW2')

        M = np.array([[0, 20, 80], [20, 50, 90], [50, 70, 100]])

        tl = 0
        hp = 3600
        for r in M:
            tl = tl + hp / r[2] * (r[1] - r[0])
        tp = tl / hp

        p._M_Windows = M

        s1 = Switch('SW1')

        s1.output_ports = {'ES2': p}

        tc = TC({'SW1': s1}, {}, '')

        cc = cost_check.CostChecker()
        cp = cc.cost(tc)
        self.assertEqual(True, cp < tp)
コード例 #9
0
    def test_dq_period_lower(self):
        p = OutputPort('SW1')
        p.queues = {None}
        p._M_Windows = np.array([[0, 0, 100]])

        p._free_period = 100

        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 50)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 25)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 12)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 6)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 3)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 1)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(p.dq_modify_period(True), False)