def test_version_5(self): vm = VirtualMachine(version=5) self.assertEqual(vm.max_chip_x, 7) self.assertEqual(vm.max_chip_y, 7) self.assertEqual(48, vm.n_chips) self.assertEqual(1, len(vm.ethernet_connected_chips)) self.assertTrue(vm.is_chip_at(4, 4)) self.assertFalse(vm.is_chip_at(0, 4)) count = sum(1 for _chip in vm.chips for _link in _chip.router.links) self.assertEqual(240, count)
def test_8_by_8(self): vm = VirtualMachine( width=8, height=8, version=None, with_wrap_arounds=False) self.assertEqual(vm.max_chip_x, 7) self.assertEqual(vm.max_chip_y, 7) self.assertEqual(48, vm.n_chips) self.assertEqual(1, len(vm.ethernet_connected_chips)) self.assertTrue(vm.is_chip_at(4, 4)) self.assertFalse(vm.is_chip_at(0, 4)) self.assertFalse((0, 4) in list(vm.chip_coordinates)) count = sum(1 for _chip in vm.chips for _link in _chip.router.links) self.assertEqual(240, count)
def test_version_2(self): vm = VirtualMachine(version=2, with_wrap_arounds=None) self.assertEqual(vm.max_chip_x, 1) self.assertEqual(vm.max_chip_y, 1) self.assertEqual(4, vm.n_chips) self.assertTrue(vm.is_chip_at(0, 0)) self.assertTrue(vm.is_chip_at(0, 1)) self.assertTrue(vm.is_chip_at(1, 0)) self.assertTrue(vm.is_chip_at(1, 1)) self.assertEqual(1, len(vm.ethernet_connected_chips)) self.assertTrue(vm.is_link_at(0, 0, 0)) self.assertTrue(vm.is_link_at(0, 0, 1)) self.assertTrue(vm.is_link_at(0, 0, 2)) self.assertFalse(vm.is_link_at(0, 0, 3)) self.assertFalse(vm.is_link_at(0, 0, 4)) self.assertTrue(vm.is_link_at(0, 0, 5)) self.assertTrue(vm.is_link_at(0, 1, 0)) self.assertTrue(vm.is_link_at(0, 1, 1)) self.assertTrue(vm.is_link_at(0, 1, 2)) self.assertFalse(vm.is_link_at(0, 1, 3)) self.assertFalse(vm.is_link_at(0, 1, 4)) self.assertTrue(vm.is_link_at(0, 1, 5)) self.assertFalse(vm.is_link_at(1, 0, 0)) self.assertFalse(vm.is_link_at(1, 0, 1)) self.assertTrue(vm.is_link_at(1, 0, 2)) self.assertTrue(vm.is_link_at(1, 0, 3)) self.assertTrue(vm.is_link_at(1, 0, 4)) self.assertTrue(vm.is_link_at(1, 0, 5)) self.assertFalse(vm.is_link_at(1, 1, 0)) self.assertFalse(vm.is_link_at(1, 1, 1)) self.assertTrue(vm.is_link_at(1, 1, 2)) self.assertTrue(vm.is_link_at(1, 1, 3)) self.assertTrue(vm.is_link_at(1, 1, 4)) self.assertTrue(vm.is_link_at(1, 1, 5)) count = 0 for _chip in vm.chips: for _link in _chip.router.links: count += 1 self.assertEqual(16, count) self.assertEqual(str(vm), "[VirtualMachine: max_x=1, max_y=1, n_chips=4]") self.assertEqual(vm.get_cores_and_link_count(), (72, 8)) count = 0 for _chip in vm.get_chips_on_board(vm.get_chip_at(1, 1)): count += 1 self.assertEqual(4, count)
def test_add_high_chip_with_down(self): down_chips = set() down_chips.add((1, 1)) vm = VirtualMachine(2, 2, down_chips=down_chips) self.assertEqual(3, vm.n_chips) _chip = self._create_chip(2, 2) vm.add_chip(_chip) self.assertEqual(vm.max_chip_x, 2) self.assertEqual(vm.max_chip_y, 2) self.assertEqual(4, vm.n_chips) self.assertTrue(vm.is_chip_at(2, 2)) _good = vm.get_chip_at(2, 2) self.assertEqual(_chip, _good) _bad = vm.get_chip_at(2, 1) self.assertIsNone(_bad) _down = vm.get_chip_at(1, 1) self.assertIsNone(_down) count = 0 for _chip in vm.chips: count += 1 self.assertTrue(4, count)
def test_add__chip(self): vm = VirtualMachine(2, 2) _chip = self._create_chip(2, 2) vm.add_chip(_chip) self.assertEqual(vm.max_chip_x, 2) self.assertEqual(vm.max_chip_y, 2) self.assertEqual(5, vm.n_chips) self.assertTrue(vm.is_chip_at(2, 2)) _good = vm.get_chip_at(2, 2) self.assertEqual(_chip, _good) _bad = vm.get_chip_at(2, 1) self.assertIsNone(_bad) count = 0 for _chip in vm.chips: count += 1 self.assertTrue(5, count)