class TestNoC(unittest.TestCase): def setUp(self): self.noc = NoC("Network-On-Chip", 4, 4, 12, [1, 1, 1, 1]) self.noc.router_linking() def test_noc_initialisation(self): self.assertEqual(len(self.noc.router_matrix), 4) self.assertEqual(self.noc.square_size, 4) def test_noc_routers(self): self.assertEqual(str(self.noc.router_matrix[0][0]), 'Router (0,0)') self.assertEqual(str(self.noc.router_matrix[3][3]), 'Router (3,3)') self.assertEqual(str(self.noc.router_matrix[2][1]), 'Router (2,1)') self.assertEqual(str(self.noc.router_matrix[1][0]), 'Router (1,0)') self.assertEqual(self.noc.router_matrix[0][0].id, 1) self.assertEqual(self.noc.router_matrix[3][3].id, 16) def test_noc_links(self): self.assertEqual(self.noc.router_matrix[0][0].outEast.inPort, self.noc.router_matrix[0][1].inWest) self.assertEqual(self.noc.router_matrix[0][0].outSouth.inPort, self.noc.router_matrix[1][0].inNorth) self.assertIsNone(self.noc.router_matrix[0][0].outNorth.inPort) self.assertIsNone(self.noc.router_matrix[0][0].outWest.inPort) self.assertEqual(self.noc.router_matrix[3][3].outNorth.inPort, self.noc.router_matrix[2][3].inSouth) self.assertEqual(self.noc.router_matrix[3][3].outWest.inPort, self.noc.router_matrix[3][2].inEast) self.assertIsNone(self.noc.router_matrix[3][3].outSouth.inPort) self.assertIsNone(self.noc.router_matrix[3][3].outEast.inPort) self.assertEqual(self.noc.router_matrix[2][2].outNorth.inPort, self.noc.router_matrix[1][2].inSouth) self.assertEqual(self.noc.router_matrix[2][2].outWest.inPort, self.noc.router_matrix[2][1].inEast) self.assertEqual(self.noc.router_matrix[2][2].outSouth.inPort, self.noc.router_matrix[3][2].inNorth) self.assertEqual(self.noc.router_matrix[2][2].outEast.inPort, self.noc.router_matrix[2][3].inWest) def test_get_router_coordinate_by_id(self): coord = self.noc.get_router_coordinate_by_id(1) self.assertEqual(coord.i, 0) self.assertEqual(coord.j, 0) coord = self.noc.get_router_coordinate_by_id(16) self.assertEqual(coord.i, 3) self.assertEqual(coord.j, 3)
class TestLink(unittest.TestCase): def setUp(self): self.noc = NoC("Network-On-Chip", 3, 4, 12, [1, 1, 1, 1]) self.noc.router_linking() def test_links_array(self): self.noc.link_array_filling() self.assertEqual(len(self.noc.links.keys()), 9) self.assertEqual(len(self.noc.links['1']), 2) self.assertEqual(len(self.noc.links['5']), 4) self.assertEqual(len(self.noc.links['2']), 3) def test_links_default_utilization_rate(self): self.noc.link_array_filling() self.assertEqual(self.noc.links['1']['2'], 0)