def test_simple():
    plan = PaymentPlanFactory(
        deposit=20,
        count=2,
        interval=1
    )
    total = Decimal('100')
    # deposit
    assert Decimal('20') == plan.deposit_amount(total)
    # instalments
    deposit_due_date = date(2015, 1, 2)
    result = plan.instalments(deposit_due_date, total)
    assert [
        (deposit_due_date + relativedelta(months=+1, day=1), Decimal('40')),
        (deposit_due_date + relativedelta(months=+2, day=1), Decimal('40')),
    ] == result
def test_illustration_awkward():
    plan = PaymentPlanFactory(
        deposit=50,
        count=3,
        interval=2
    )
    total = Decimal('200')
    # deposit
    assert Decimal('100') == plan.deposit_amount(total)
    # instalments
    deposit_due_date = date(2015, 1, 2)
    result = plan.instalments(deposit_due_date, total)
    assert [
        (deposit_due_date + relativedelta(months=+2, day=1), Decimal('33.33')),
        (deposit_due_date + relativedelta(months=+4, day=1), Decimal('33.33')),
        (deposit_due_date + relativedelta(months=+6, day=1), Decimal('33.34')),
    ] == result
def test_illustration_typical():
    plan = PaymentPlanFactory(
        deposit=15,
        count=6,
        interval=1
    )
    total = Decimal('600')
    # deposit
    assert Decimal('90') == plan.deposit_amount(total)
    # instalments
    deposit_due_date = date(2015, 1, 22)
    result = plan.instalments(deposit_due_date, total)
    assert [
        (deposit_due_date + relativedelta(months=+2, day=1), Decimal('85')),
        (deposit_due_date + relativedelta(months=+3, day=1), Decimal('85')),
        (deposit_due_date + relativedelta(months=+4, day=1), Decimal('85')),
        (deposit_due_date + relativedelta(months=+5, day=1), Decimal('85')),
        (deposit_due_date + relativedelta(months=+6, day=1), Decimal('85')),
        (deposit_due_date + relativedelta(months=+7, day=1), Decimal('85')),
    ] == result