Exemple #1
0
def balance_cost(cost: Iterable[float], partitions: int) -> List[int]:
    partitioned = blockpartition.solve(list(cost), partitions)
    return [len(p) for p in partitioned]
Exemple #2
0
def balance_cost(cost: List[int], partitions: int) -> List[int]:
    partitioned = blockpartition.solve(cost, partitions)
    return [len(p) for p in partitioned]
Exemple #3
0
def test_blockpartition():
    assert blockpartition.solve([1, 2, 3, 4, 5, 6],
                                partitions=2) == [[1, 2, 3, 4], [5, 6]]
Exemple #4
0
def test_blockpartition_short_sequence():
    with pytest.raises(ValueError):
        blockpartition.solve([], partitions=1)
    with pytest.raises(ValueError):
        blockpartition.solve([42], partitions=2)
Exemple #5
0
def test_blockpartition_non_positive_partitions():
    with pytest.raises(ValueError):
        blockpartition.solve([42], partitions=0)
    with pytest.raises(ValueError):
        blockpartition.solve([42], partitions=-1)
Exemple #6
0
def test_blockpartition_zeros():
    assert blockpartition.solve([0, 0], partitions=2) == [[0], [0]]