from src.multiples import Multiple, MultiplesInMem, MultiplesOnDisk


def test_multiplesinmem():
    max_val = 10_000
    multiples_max_value = 2_000
    expected_values = [exp for exp in range(1, max_val + 1)]

    actuals = MultiplesInMem(multiples_max_value)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, False))
    assert len(actuals) == 10_000
    assert [actual.p_val for actual in actuals] == expected_values
    for actual in actuals:
        assert actual.start_val == 1

    actuals = MultiplesInMem(multiples_max_value)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, True))
    for a, e in zip(actuals, expected_values):
        assert a.p_val == e

    actuals = MultiplesInMem(multiples_max_value)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, False))
    actuals.advance(multiples_max_value)
    for a, e in zip(actuals, expected_values):
        assert a.p_val == e


def test_multiplesondisk():
    max_val = 10_000
    multiples_max_value = 2_000
    expected_values = [exp for exp in range(1, max_val + 1)]
    max_mem_buffer = 1_000

    actuals = MultiplesOnDisk(max_val, max_mem_buffer)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, False))
    assert len(actuals) == 10_000
    assert [actual.p_val for actual in actuals] == expected_values
    for actual in actuals:
        assert actual.start_val == 1

    actuals = MultiplesOnDisk(max_val, max_mem_buffer)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, True))
    for a, e in zip(actuals, expected_values):
        assert a.p_val == e

    actuals = MultiplesOnDisk(max_val, max_mem_buffer)
    for p_val in expected_values:
        actuals.append(Multiple(1, p_val, multiples_max_value, False))
    actuals.advance(multiples_max_value)
    for a, e in zip(actuals, expected_values):
        assert a.p_val == e
