コード例 #1
0
 def test_get_group_with_all_group_and_matrix_type_combinations(self):
     """
     Tests the `get_group` method with every combination of group type
     and matrix type
     """
     test_cases = product(self.get_group_definitions(), self.get_matrices())
     for (group_name, group_definition), (matrix_name, matrix) in test_cases:
         with self.subTest(matrix=matrix_name, group=group_name):
             row_grouper = RowGrouper(group_definition)
             for group_id in row_grouper.ids:
                 with self.subTest(group_id=group_id):
                     # Get the group members the boring way using pure
                     # Python
                     expected_value = self.get_group(
                         group_definition, matrix, group_id
                     )
                     value = row_grouper.get_group(matrix, group_id)
                     self.assertEqual(to_list_of_lists(value), expected_value)
コード例 #2
0
 def test_basic_get_group(self):
     """
     Test fetching members for a single group on a matrix which is small
     enough to verify the results by hand
     """
     # fmt: off
     group_definition = [(0, "even"), (1, "odd"), (2, "even"), (3, "odd")]
     rows = [
         [1, 2, 3, 4],
         [2, 3, 4, 5],
         [3, 4, 5, 6],
         [4, 5, 6, 7]
     ]
     expected_value = [
         [1, 2, 3, 4],
         [3, 4, 5, 6]
     ]
     # fmt: on
     matrix = numpy.array(rows)
     row_grouper = RowGrouper(group_definition)
     group = row_grouper.get_group(matrix, "even")
     self.assertEqual(to_list_of_lists(group), expected_value)