diff --git a/spinn_machine/routing_entry.py b/spinn_machine/routing_entry.py index b8ac9f03..d9ed8e8f 100644 --- a/spinn_machine/routing_entry.py +++ b/spinn_machine/routing_entry.py @@ -80,6 +80,7 @@ def __init__(self, *, if spinnaker_route is None: assert processor_ids is not None assert link_ids is not None + assert defaultable is None if isinstance(processor_ids, int): processor_ids = [processor_ids] if isinstance(link_ids, int): @@ -103,9 +104,6 @@ def __init__(self, *, "incoming_processor", incoming_processor, "The incoming direction for a path can only be from " "either one link or one processors, not both") - # TODO remove this GIGO! - if defaultable is not None: - self._defaultable: bool = defaultable else: assert processor_ids is None assert link_ids is None diff --git a/unittests/test_multicast_routing_entry.py b/unittests/test_multicast_routing_entry.py index 26489fac..7b5a396f 100644 --- a/unittests/test_multicast_routing_entry.py +++ b/unittests/test_multicast_routing_entry.py @@ -34,8 +34,7 @@ def test_creating_new_multicast_routing_entry(self): key = 1 mask = 1 a_multicast = MulticastRoutingEntry( - key, mask, RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, defaultable=True)) + key, mask, RoutingEntry(processor_ids=proc_ids, link_ids=link_ids)) self.assertEqual(a_multicast.key, key) self.assertEqual(a_multicast.link_ids, set(link_ids)) @@ -45,7 +44,30 @@ def test_creating_new_multicast_routing_entry(self): self.assertEqual( str(a_multicast), "1:1:{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, " - "16, 17}:{0, 1, 2, 3, 4, 5}(defaultable)") + "16, 17}:{0, 1, 2, 3, 4, 5}") + self.assertEqual( + a_multicast, + pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL))) + hash(a_multicast) + + def test_creating_defaulatble_multicast_routing_entry(self): + link_ids = list() + proc_ids = list() + link_ids.append(2) + key = 1 + mask = 1 + a_multicast = MulticastRoutingEntry( + key, mask, RoutingEntry( + processor_ids=proc_ids, link_ids=link_ids, incoming_link=5)) + + self.assertEqual(a_multicast.key, key) + self.assertEqual(a_multicast.link_ids, set(link_ids)) + self.assertEqual(a_multicast.mask, mask) + self.assertEqual(a_multicast.processor_ids, set(proc_ids)) + # While we're here, let's check a few other basic operations + self.assertEqual( + str(a_multicast), + "1:1:{}:{2}(defaultable)") self.assertEqual( a_multicast, pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL))) @@ -85,9 +107,9 @@ def test_merger(self): mask = 1 a_multicast = MulticastRoutingEntry( key, mask, RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, defaultable=True)) + processor_ids=proc_ids, link_ids=link_ids)) b_multicast = MulticastRoutingEntry(key, mask, RoutingEntry( - processor_ids=proc_ids2, link_ids=link_ids2, defaultable=True)) + processor_ids=proc_ids2, link_ids=link_ids2)) result_multicast = a_multicast.merge(b_multicast) comparison_link_ids = list() @@ -107,43 +129,22 @@ def test_merger(self): set(comparison_proc_ids)) def test_merger_with_different_defaultable(self): - link_ids = list() - link_ids2 = list() - proc_ids = list() - proc_ids2 = list() - for i in range(3): - link_ids.append(i) - for i in range(3, 6): - link_ids2.append(i) - for i in range(9): - proc_ids.append(i) - for i in range(9, 18): - proc_ids2.append(i) key = 1 mask = 1 a_multicast = MulticastRoutingEntry(key, mask, RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, defaultable=True)) + processor_ids=[], link_ids=[3], incoming_link=6)) + assert a_multicast.defaultable b_multicast = MulticastRoutingEntry(key, mask, RoutingEntry( - processor_ids=proc_ids2, link_ids=link_ids2, defaultable=False)) + processor_ids=[], link_ids=[3], incoming_link=4)) + assert not b_multicast.defaultable result_multicast = a_multicast.merge(b_multicast) - comparison_link_ids = list() - comparison_proc_ids = list() - for i in range(6): - comparison_link_ids.append(i) - self.assertEqual(link_ids + link_ids2, comparison_link_ids) - for i in range(18): - comparison_proc_ids.append(i) - self.assertEqual(proc_ids + proc_ids2, comparison_proc_ids) self.assertEqual(result_multicast.key, key) - self.assertEqual(result_multicast.link_ids, - set(comparison_link_ids)) + self.assertEqual(result_multicast.link_ids, set([3])) self.assertEqual(result_multicast.mask, mask) - self.assertEqual(result_multicast.processor_ids, - set(comparison_proc_ids)) - self.assertNotEqual(result_multicast, a_multicast) - self.assertNotEqual(result_multicast, b_multicast) + self.assertEqual(result_multicast.processor_ids, set()) + assert not result_multicast.defaultable def test_merger_with_invalid_parameter_key(self): link_ids = list() @@ -161,7 +162,7 @@ def test_merger_with_invalid_parameter_key(self): key_combo = 1 mask = 1 entry = RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, defaultable=True) + processor_ids=proc_ids, link_ids=link_ids) a_multicast = MulticastRoutingEntry(key_combo, mask, entry) b_multicast = MulticastRoutingEntry(key_combo + 1, mask + 1, entry) with self.assertRaises(SpinnMachineInvalidParameterException) as e: @@ -186,9 +187,9 @@ def test_merger_with_invalid_parameter_mask(self): key = 0 mask = 2 a_multicast = MulticastRoutingEntry(key, mask, RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, defaultable=True)) + processor_ids=proc_ids, link_ids=link_ids)) b_multicast = MulticastRoutingEntry(key, 4, RoutingEntry( - processor_ids=proc_ids2, link_ids=link_ids2, defaultable=True)) + processor_ids=proc_ids2, link_ids=link_ids2)) self.assertNotEqual(a_multicast, b_multicast) self.assertNotEqual(a_multicast, "foo") with self.assertRaises(SpinnMachineInvalidParameterException): diff --git a/unittests/test_routing_entry.py b/unittests/test_routing_entry.py index 835c200a..3cc2c59e 100644 --- a/unittests/test_routing_entry.py +++ b/unittests/test_routing_entry.py @@ -31,15 +31,28 @@ def test_creating_new_routing_entry(self): for i in range(18): proc_ids.append(i) a_multicast = RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, - defaultable=True) + processor_ids=proc_ids, link_ids=link_ids) self.assertEqual(a_multicast.link_ids, set(link_ids)) self.assertEqual(a_multicast.processor_ids, set(proc_ids)) # While we're here, let's check a few other basic operations self.assertEqual(str(a_multicast), "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, " - "15, 16, 17}:{0, 1, 2, 3, 4, 5}(defaultable)") + "15, 16, 17}:{0, 1, 2, 3, 4, 5}") + self.assertEqual( + a_multicast, + pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL))) + hash(a_multicast) + + def test_defualtable_routing_entry(self): + a_multicast = RoutingEntry( + processor_ids=[], link_ids=[4], incoming_link=1) + + self.assertEqual(a_multicast.link_ids, set([4])) + self.assertEqual(a_multicast.processor_ids, set()) + # While we're here, let's check a few other basic operations + self.assertEqual(str(a_multicast), + "{}:{4}(defaultable)") self.assertEqual( a_multicast, pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL))) @@ -69,12 +82,8 @@ def test_merger(self): proc_ids.append(i) for i in range(9, 18): proc_ids2.append(i) - a_multicast = RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, - defaultable=True) - b_multicast = RoutingEntry( - processor_ids=proc_ids2, link_ids=link_ids2, - defaultable=True) + a_multicast = RoutingEntry(processor_ids=proc_ids, link_ids=link_ids) + b_multicast = RoutingEntry(processor_ids=proc_ids2, link_ids=link_ids2) result_multicast = a_multicast.merge(b_multicast) comparison_link_ids = list() @@ -91,40 +100,17 @@ def test_merger(self): set(comparison_proc_ids)) def test_merger_with_different_defaultable(self): - link_ids = list() - link_ids2 = list() - proc_ids = list() - proc_ids2 = list() - for i in range(3): - link_ids.append(i) - for i in range(3, 6): - link_ids2.append(i) - for i in range(9): - proc_ids.append(i) - for i in range(9, 18): - proc_ids2.append(i) a_multicast = RoutingEntry( - processor_ids=proc_ids, link_ids=link_ids, - defaultable=True) + processor_ids=[], link_ids=[1], incoming_link=4) b_multicast = RoutingEntry( - processor_ids=proc_ids2, link_ids=link_ids2, - defaultable=False) + processor_ids=[], link_ids=[1], incoming_link=5) result_multicast = a_multicast.merge(b_multicast) - comparison_link_ids = list() - comparison_proc_ids = list() - for i in range(6): - comparison_link_ids.append(i) - self.assertEqual(link_ids + link_ids2, comparison_link_ids) - for i in range(18): - comparison_proc_ids.append(i) - self.assertEqual(proc_ids + proc_ids2, comparison_proc_ids) - self.assertEqual(result_multicast.link_ids, set(comparison_link_ids)) - self.assertEqual(result_multicast.processor_ids, - set(comparison_proc_ids)) + self.assertEqual(result_multicast.link_ids, set([1])) + self.assertEqual(result_multicast.processor_ids, set()) self.assertNotEqual(result_multicast, a_multicast) - self.assertNotEqual(result_multicast, b_multicast) + self.assertNotEqual(hash(result_multicast), hash(a_multicast)) """ From FixedRouteEntry use or loose