Beispiel #1
0
    def test_best_fit_multiple_spaces(self):
        '''
        assert that if a item is smaller than the box, but has two dimensions
        the same, it will return the empty space
        '''
        item_dims = [13, 13, 31]
        box_dims = [20, 20, 31]

        remaining_space = best_fit(item_dims, box_dims)
        self.assertEqual(remaining_space, [[7, 13, 31], [7, 20, 31]])
Beispiel #2
0
    def test_best_fit_exact_size(self):
        '''
        assert that if a item is the same size as the box,
        the remaining_dimensions comes back empty
        '''
        item_dims = [13, 13, 31]
        box_dims = [13, 13, 31]

        remaining_space = best_fit(item_dims, box_dims)
        self.assertEqual(remaining_space, [])
Beispiel #3
0
    def test_best_fit_half_size(self):
        '''
        assert that if a item is smaller than the box, but has two dimensions
        the same, it will return the empty space
        '''
        item_dims = [13, 13, 31]
        box_dims = [13, 26, 31]

        remaining_space = best_fit(item_dims, box_dims)
        self.assertEqual(remaining_space, [[13, 13, 31]])
Beispiel #4
0
def space_after_packing(item_info, box_info):
    '''
    returns the remaining space in a box after packing a item and
        the remaining block sizes within the box after an ideal fit
    assumes item and box dimensions are in the same units

    Args:

        product_info (Dict[{
                width: float
                height: float
                length: float
                weight: float
            }])
        box_info (Dict[{
                width: float
                height: float
                length: float
                weight: float
            }])

    Returns
        Dict[{
            'remaining_volume': float
            'remaining_dimensional_blocks': List[List[int, int, int]]
        }]
    '''

    item_dims = sorted(
        [item_info['width'], item_info['height'], item_info['length']])
    box_dims = sorted(
        [box_info['width'], box_info['height'], box_info['length']])

    if not does_it_fit(item_dims, box_dims):
        raise BoxError(
            'Product with dimensions {} does not fit into a box with'
            ' dimensions {}'.format('X'.join(map(str, item_dims)),
                                    'X'.join(map(str, item_dims))))
    remaining_dimensions = best_fit(item_dims, box_dims)
    blocks = [{
        'width': block[0],
        'height': block[1],
        'length': block[2]
    } for block in remaining_dimensions]
    remaining_volume = sum(volume(block) for block in remaining_dimensions)

    return {
        'remaining_volume': remaining_volume,
        'remaining_dimensional_blocks': blocks
    }