示例#1
0
    def test_count__1block(self):
        count_10_12 = calculate_count([10], 12)
        count_2_4 = calculate_count([2], 4)
        count_1_3 = calculate_count([1], 3)

        self.assertEqual(count_10_12, 3)
        self.assertEqual(count_2_4, 3)
        self.assertEqual(count_1_3, 3)
示例#2
0
    def test_count__2block(self):
        count_2_2__6 = calculate_count([2, 2], 6)
        count_2_1__5 = calculate_count([2, 1], 5)
        count_1_1__4 = calculate_count([1, 1], 4)

        self.assertEqual(count_2_2__6, 3)
        self.assertEqual(count_2_1__5, 3)
        self.assertEqual(count_1_1__4, 3)
示例#3
0
        def inplace():
            self.metrics.add_event(('sub_collapse', 'inplace'))
            move_space = calculate_moves(task, len(field_line))
            if len(task) == 1 and move_space == 0:
                return CollapseResult.filled(len(field_line), 1)

            count = calculate_count(task, len(field_line))
            if move_space >= max(task):
                return CollapseResult.empty(len(field_line), count)

            def stack_left_ends():
                start = 0
                for block in task:
                    yield start + block
                    start += block + MIN_BLOCK_SPACE

            def stack_right_starts():
                start = move_space
                for block in task:
                    yield start
                    start += block + MIN_BLOCK_SPACE

            filled_indecies = [
                i
                for start, end in zip(stack_right_starts(), stack_left_ends())
                for i in range(start, end)
            ]

            line = np.full(len(field_line), Cell.EMPTY, Cell.dtype)
            line[filled_indecies] = Cell.FILLED
            return CollapseResult(line, count)
示例#4
0
        def count(order, index, task, length):
            with self.log.init_line(order, index, task=task) as init_end:
                start = perf_counter_ns()

                line_id = order + str(index)
                count = calculate_count(task, length)

                dt = perf_counter_ns() - start
                self.metrics.add_event(('init', line_id))
                self.metrics.add_value(('init.time', line_id), dt)
                self.metrics.add_value(('complexity', line_id), count)

                init_end(count=count)
                return count
示例#5
0
    def test_count__4block(self):
        count = calculate_count([6, 2, 16, 1], 35)

        self.assertEqual(count, 330)