def test_get_groups_with_mines(self): expected = [ Group({(0, 0), (0, 1), (0, 2), (1, 0), (2, 0), (2, 2)}, 3), Group({(1, 0), (2, 0), (2, 2), (3, 0), (3, 1), (3, 2)}, 2) ] groups = parser.parse_game('inputs/002').groups self.assertEqual(expected, groups)
def test_subgroup(self): g1 = Group({1, 2}, 1) g2 = Group({1, 2, 3}, 1) groups = [g1, g2] groups_solver.operate_groups(groups) self.assertEqual(2, len(groups)) self.assertEqual(Group({1, 2}, 1), groups[0]) self.assertEqual(Group({3}, 0), groups[1])
def test_ignore_empty_cells(self): expected_first_five = [ Group({(0, 0), (1, 0), (2, 0), (0, 1), (0, 2)}, 3), Group({(0, 1), (0, 2), (0, 3)}, 2), Group({(0, 2), (0, 3), (0, 4)}, 2), Group({(0, 3), (0, 4), (0, 5)}, 1), Group({(0, 4), (0, 5), (0, 6), (1, 6), (2, 6)}, 3), ] groups = parser.parse_game('inputs/005').groups self.assertEqual(expected_first_five, groups[0:5])
def test_intersection(self): g1 = Group({1, 2, 3}, 1) g2 = Group({2, 3, 4, 5}, 3) groups = [g1, g2] groups_solver.operate_groups(groups) self.assertEqual(3, len(groups)) self.assertEqual(Group({1}, 0), groups[0]) self.assertEqual(Group({4, 5}, 2), groups[1]) self.assertEqual(Group({2, 3}, 1), groups[2])
def test_get_cells(self): g1 = Group({1, 2, 3}, 3) g2 = Group({4, 5}, 1) g3 = Group({5, 6}, 0) g4 = Group({7, 8, 9}, 2) mines, not_mines = groups_solver.get_reliable_cells([g1, g2, g3, g4]) self.assertEqual(3, len(mines)) self.assertEqual(g1.cells, mines) self.assertEqual(2, len(not_mines)) self.assertEqual(g3.cells, not_mines)
def test_equal_groups(self): g = Group({1, 2, 3}, 2) groups = [g, g] groups_solver.operate_groups(groups) self.assertEqual(1, len(groups)) self.assertEqual(g, groups[0])
def __handleTable(self): workbook = self.workbook groups = {} for sheet_name in workbook.sheet_names(): sheet = workbook.sheet_by_name(sheet_name) group_row = sheet.row_values(settings['group_number']['row'], settings['group_number']['start_col'], settings['group_number']['stop_col']) for i, group_name in enumerate(group_row): if not group_name: continue if not group_name in groups.keys(): groups[group_name] = {} col_delta = settings['group_number']['start_col'] for j, next_group in enumerate(group_row[i + 1:]): if not next_group: continue rng = (i + col_delta, j + col_delta + 1) break else: rng = (i + col_delta, len(group_row) + col_delta) for index in range(0, int((rng[1] - rng[0]) / 2)): start_rng = rng[0] + 2 * index g = Group(name=group_name, _range=(start_rng, start_rng + 2), sheet=sheet) groups[group_name][index] = g.getInfo() return groups
def test_add_children(self): ref = Group() child1 = Session() child2 = Session() ref.add_child(child1) ref.add_child(child2) self.assertEqual([child1, child2], ref.children)
def group_shapes(self, x, y, length, width): group_list = [] bool_check = False for shape in reversed(self.shapes): if shape.is_shape_in_region(x, y, length, width): bool_check = True group_list.append(shape) self.shapes.remove(shape) if bool_check: self.shapes.append(Group(list(reversed(group_list))))
def test_load_config(self): ref = Group() ref.load_configuration({ 'name': 'test_name', 'description': 'test_desc', 'plot_settings': 'test_settings' }) self.assertEqual(ref.name, 'test_name') self.assertEqual(ref.description, 'test_desc') self.assertEqual(ref.plot_settings, 'test_settings')
def __create_group(field, area, w): cells = set() for i, j in area: if field[i][j] == conf.UNOPENED_CELL: cells.add((i, j)) elif field[i][j] == conf.MINE: w -= 1 if w < 0: raise ParseException( ErrorMessages.LOW_CORRECTED_WEIGHT.format(sorted(area))) return Group(cells, w) if len(cells) > 0 else None
def operate_groups(groups): result = False size = len(groups) i = 0 while i < size - 1: j = i while j + 1 < size: j += 1 g1, g2 = groups[i], groups[j] if g1.cells == g2.cells: if g1.w == g2.w: del groups[i] j -= 1 size -= 1 result = True continue else: raise SolveException( 'Conflict in groups, check cells near {}'.format( g1.cells)) parent, child = (g1, g2) if len(g1.cells) >= len(g2.cells) else (g2, g1) if parent.cells >= child.cells: parent.subtract(child) result = True continue parent, child = (g1, g2) if g1.w >= g2.w else (g2, g1) intersection = parent.cells & child.cells if intersection and parent.w - child.w == len( parent.cells) - len(intersection): new_group = Group(intersection, child.w) parent.subtract(new_group) child.subtract(new_group) groups.append(new_group) result = True continue i += 1 return result
def setUp(self): self.mock_db_handler = MagicMock() self.group = Group(self.mock_db_handler)
def test_ungroup_a_nonexistent_group_from_a_diagram(self): group = Group([Circle(10, 10, 5), Circle(20, 20, 5)]) self.diagram.ungroup(group) self.assertEqual(0, len(self.diagram.shapes))
def test_load_stimuli(self, mock_stim): ref = Group() ref.load_stimuli('src/tests/test-data/stimuli.mat', 0.5) mock_stim.assert_called_once_with('src/tests/test-data/stimuli.mat', 0.5)
def test_load_anatomy(self, mock_brain): ref = Group() ref.load_anatomy('src/tests/test-data/mask.nii') mock_brain.assert_called_once_with('src/tests/test-data/mask.nii')
def test_load_mask(self, mock_mask): ref = Group() ref.load_mask('src/tests/test-data/mask.nii') mock_mask.assert_called_once_with('src/tests/test-data/mask.nii')
def test_aggregate(self, mock_sett_change, mock_aggr): ref = Group() ref.aggregate() mock_sett_change.assert_called_once_with(ref, None, None, None, None) mock_aggr.assert_called_once_with(ref, None, None, None, None)
def group(): from src.group import Group group = Group() print('\n') yield group
def test_group(self, mock_load): Group('test.json') mock_load.assert_called_once_with('test.json')