Пример #1
0
def test_kv_reductionby__no_perpartition_single_argument():
    seq = [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]]
    transform = kv_reductionby(sum)
    actual = sorted(transform(seq))
    expected = sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])

    assert actual == expected
Пример #2
0
def test_kv_reductionby__no_perpartition_single_argument():
    seq = [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]]
    transform = kv_reductionby(sum)
    actual = sorted(transform(seq))
    expected = sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])

    assert actual == expected
Пример #3
0
def test_kv_reductionby__no_perpartition(executor):
    actual = executor(
        kv_reductionby(None, sum),
        [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]],
        npartitions=3,
    )

    assert sorted(actual) == sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])
Пример #4
0
def test_kv_reductionby__with_perpartition():
    seq = [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]]
    transform = kv_reductionby(
        lambda x: x,
        lambda parts: sum(i for part in parts for i in part),
    )
    actual = sorted(transform(seq))
    expected = sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])

    assert actual == expected
Пример #5
0
def test_kv_reductionby__with_perpartition():
    seq = [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]]
    transform = kv_reductionby(
        lambda x: x,
        lambda parts: sum(i for part in parts for i in part),
    )
    actual = sorted(transform(seq))
    expected = sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])

    assert actual == expected
Пример #6
0
def test_kv_reductionby__with_perpartition(executor):
    actual = executor(
        kv_reductionby(
            lambda x: x,
            lambda parts: sum(i for part in parts for i in part),
        ),
        [(i % 2, i) for i in [1, 2, 3, 4, 5, 6, 7]],
        npartitions=3,
    )

    assert sorted(actual) == sorted([
        (1, sum([1, 3, 5, 7])),
        (0, sum([2, 4, 6])),
    ])