예제 #1
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
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
파일: test_group.py 프로젝트: pfechd/jabe
    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)
예제 #5
0
파일: test_group.py 프로젝트: pfechd/jabe
    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')
예제 #6
0
    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_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])
예제 #8
0
    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 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])
예제 #12
0
파일: test_group.py 프로젝트: pfechd/jabe
    def test_calculate_fwhm(self):
        fn = lambda x: -x ** 2 + 20 * x
        test_y = [fn(x) for x in range(21)]
        test_x = np.arange(len(test_y))

        r1, r2 = Group.calculate_fwhm(test_x, test_y, 20)

        self.assertEqual(fn(r1), 50)
        self.assertEqual(fn(r2), 50)

        fn = lambda x: x ** 3 - 30 * x ** 2 + 200 * x
        test_y = [fn(x) for x in range(23)]
        test_x = np.arange(len(test_y))

        r1, r2 = Group.calculate_fwhm(test_x, test_y, 20)

        self.assertEqual((r1, r2), (0, 1))
예제 #13
0
    def test_calculate_fwhm(self):
        fn = lambda x: -x**2 + 20 * x
        test_y = [fn(x) for x in range(21)]
        test_x = np.arange(len(test_y))

        r1, r2 = Group.calculate_fwhm(test_x, test_y, 20)

        self.assertEqual(fn(r1), 50)
        self.assertEqual(fn(r2), 50)

        fn = lambda x: x**3 - 30 * x**2 + 200 * x
        test_y = [fn(x) for x in range(23)]
        test_x = np.arange(len(test_y))

        r1, r2 = Group.calculate_fwhm(test_x, test_y, 20)

        self.assertEqual((r1, r2), (0, 1))
예제 #14
0
    def test_calculate_amplitude(self):
        fn = lambda x: -x**2 + 20 * x
        test_y = [fn(x) for x in range(21)]
        test_x = np.arange(len(test_y))

        x, max_amp = Group.calculate_amplitude(test_x, test_y, 20)

        self.assertEqual(x, 10)
        self.assertEqual(round(max_amp), 100)
예제 #15
0
파일: test_group.py 프로젝트: pfechd/jabe
    def test_calculate_amplitude(self):
        fn = lambda x: -x ** 2 + 20 * x
        test_y = [fn(x) for x in range(21)]
        test_x = np.arange(len(test_y))

        x, max_amp = Group.calculate_amplitude(test_x, test_y, 20)

        self.assertEqual(x, 10)
        self.assertEqual(round(max_amp), 100)
예제 #16
0
    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))))
예제 #17
0
    def load_groups(self):
        path = self.line_edit_application_file.text()

        test_name_regex = re.compile(r'.+\s\d\d:\d\d')
        student_regex = re.compile(r'\s+[+✔]\s+(\D+)\s(\d+)\s(.*)\s?')

        self.groups = []
        for part in GroupInfos.split_file_into_parts(path, test_name_regex):
            group_name = test_name_regex.search(part[0]).group(0)
            group = Group(group_name, 'Test')

            for line in part[1:]:
                match = student_regex.search(line)
                if match:
                    group.add_student(Student(*([match.group(i) for i in range(1, 4)] + [group_name])))

            self.groups.append(group)

        group_names = [group.name for group in self.groups]
        self.list_groups.clear()
        self.list_groups.addItems(group_names)
예제 #18
0
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
예제 #19
0
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
예제 #20
0
 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))
예제 #21
0
파일: test_group.py 프로젝트: pfechd/jabe
    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)
예제 #22
0
파일: test_group.py 프로젝트: pfechd/jabe
    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')
예제 #23
0
파일: test_group.py 프로젝트: pfechd/jabe
    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')
예제 #24
0
파일: test_group.py 프로젝트: pfechd/jabe
 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)
예제 #25
0
 def test_group(self, mock_load):
     Group('test.json')
     mock_load.assert_called_once_with('test.json')
예제 #26
0
    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)
예제 #27
0
    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')
예제 #28
0
 def setUp(self):
     self.mock_db_handler = MagicMock()
     self.group = Group(self.mock_db_handler)
예제 #29
0
class TestGroup(unittest.TestCase):
    """
    Tests for the Group class
    """
    def setUp(self):
        self.mock_db_handler = MagicMock()
        self.group = Group(self.mock_db_handler)

    # Test adding a group
    def test_add_group(self):
        self.mock_db_handler.create.return_value = 'test'
        expected_result = {
            'description': 'group',
            'group_id': 45,
            'name': 'marx'
        }
        with app.test_request_context('group/45',
                                      json={
                                          'name': 'marx',
                                          'description': 'group'
                                      }):
            actual_result = self.group.add_group(45)
            self.assertEqual(expected_result, actual_result)

    # Test viewing a group
    def test_view_group(self):
        self.mock_db_handler.find.return_value = {
            'name': 'marx',
            'description': 'group',
            '_id': 45
        }
        expected_result = {'description': 'group', 'name': 'marx'}
        with app.test_request_context('group/45',
                                      json={
                                          'name': 'marx',
                                          'description': 'group'
                                      }):
            actual_result = self.group.view_group(45)
            self.assertEqual(expected_result, actual_result)

    # Test deleting a group
    def test_delete_group(self):
        self.mock_db_handler.find.return_value = 'foo'
        expected_result = None
        with app.test_request_context('group/45'):
            actual_result = self.group.delete_group('45')
            self.assertEqual(expected_result, actual_result)

    # Test updating a group
    def test_update_group(self):
        self.mock_db_handler.create.return_value = {
            'name': 'marx',
            'description': 'group'
        }
        expected_result = {'name': 'marx', 'description': 'group'}
        with app.test_request_context('group/45',
                                      json={
                                          'name': 'marx',
                                          'description': 'group'
                                      }):
            actual_result = self.group.update_group(45)
            self.assertEqual(expected_result, actual_result)

    # Test recommending a group
    def test_recommend_group(self):
        self.mock_db_handler.create.return_value = 'test'
        expected_result = {
            'description': 'group',
            'group_id': 45,
            'name': 'marx'
        }
        with app.test_request_context('group/45',
                                      json={
                                          'name': 'marx',
                                          'description': 'group'
                                      }):
            actual_result = self.group.recommend_group(45)
            self.assertEqual(expected_result, actual_result)
예제 #30
0
def group():
    from src.group import Group

    group = Group()
    print('\n')
    yield group
예제 #31
0
    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')
예제 #32
0
 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)