| 20 | |
| 21 | |
| 22 | class BinaryPartitionUtilsTest(unittest.TestCase): |
| 23 | @parameterized.parameterized.expand( |
| 24 | [ |
| 25 | (PARTITION_NO_DUPLICATE_PROC_ID, False), |
| 26 | (PARTITION_NO_DUPLICATE_PROC_ID.right, False), |
| 27 | (PARTITION_NO_DUPLICATE_PROC_ID.left, True), |
| 28 | (PARTITION_DUPLICATE_PROC_ID, False), |
| 29 | (PARTITION_DUPLICATE_PROC_ID.right, False), |
| 30 | (PARTITION_DUPLICATE_PROC_ID.left, True), |
| 31 | ] |
| 32 | ) |
| 33 | def test_is_leaf_node(self, partition, expected_leaf_status): |
| 34 | self.assertEqual(bpu.is_leaf_node(partition), expected_leaf_status) |
| 35 | |
| 36 | @parameterized.parameterized.expand( |
| 37 | [ |
| 38 | (PARTITION_NO_DUPLICATE_PROC_ID, CHUNK_OWNERS_NO_DUPLICATE_PROC_ID), |
| 39 | (PARTITION_DUPLICATE_PROC_ID, CHUNK_OWNERS_DUPLICATE_PROC_ID), |
| 40 | ] |
| 41 | ) |
| 42 | def test_enumerate_leaf_nodes(self, partition, chunk_owners): |
| 43 | leaf_nodes = list(bpu.enumerate_leaf_nodes(partition)) |
| 44 | self.assertEqual(len(leaf_nodes), partition.numchunks()) |
| 45 | proc_ids = [node.proc_id for node in bpu.enumerate_leaf_nodes(partition)] |
| 46 | self.assertEqual(proc_ids, list(chunk_owners)) # depth first ordering |
| 47 | |
| 48 | def test_partition_has_duplicate_proc_ids(self): |
| 49 | self.assertFalse( |
| 50 | bpu.partition_has_duplicate_proc_ids(PARTITION_NO_DUPLICATE_PROC_ID) |
| 51 | ) |
| 52 | self.assertTrue( |
| 53 | bpu.partition_has_duplicate_proc_ids(PARTITION_DUPLICATE_PROC_ID) |
| 54 | ) |
| 55 | |
| 56 | @parameterized.parameterized.expand( |
| 57 | [ |
| 58 | ( |
| 59 | PARTITION_NO_DUPLICATE_PROC_ID, |
| 60 | [0, 1, 2, 3, 4], |
| 61 | ), |
| 62 | ( |
| 63 | PARTITION_DUPLICATE_PROC_ID, |
| 64 | [0, 1, 2, 3, 4], |
| 65 | ), |
| 66 | ] |
| 67 | ) |
| 68 | def test_get_total_weight(self, partition, weights_by_proc_id): |
| 69 | if not bpu.partition_has_duplicate_proc_ids(partition): |
| 70 | self.assertEqual( |
| 71 | bpu.get_total_weight(partition, weights_by_proc_id), |
| 72 | sum(weights_by_proc_id), |
| 73 | ) |
| 74 | self.assertEqual( |
| 75 | bpu.get_total_weight(partition.right.left, weights_by_proc_id), |
| 76 | weights_by_proc_id[1] + weights_by_proc_id[4] + weights_by_proc_id[3], |
| 77 | ) |
| 78 | else: |
| 79 | with self.assertRaises(ValueError): |
nothing calls this directly
no outgoing calls
no test coverage detected