Пример #1
0
def test_make_even_sanity_with_failure():
    b1 = ('b1', {'name':'b1', 'amount': Decimal(-5)})
    s1 = ('s1', {'name':'s1', 'amount': Decimal(1.5)})

    invalidBorrowers = [b1]
    invalidSponsors = [s1]

    with pytest.raises(ValueError):
        deptCalculator.makeEven(invalidBorrowers, invalidSponsors, Decimal(0))
Пример #2
0
def test_make_even_sanity():
    b1 = ('b1', {'name':'b1', 'amount': Decimal(-5)})
    b2 = ('b2', {'name':'b2', 'amount': Decimal(-7)})
    b3 = ('b3', {'name':'b3', 'amount': Decimal(-9)})
    
    s1 = ('s1', {'name':'s1', 'amount': Decimal(1.5)})
    s2 = ('s2', {'name':'s2', 'amount': Decimal(3)})
    s3 = ('s3', {'name':'s3', 'amount': Decimal(16.5)})

    expectedResult = [{'borrower':{'name':'b3'},'amount': 9,'sponsor':{'name':'s3'}},
                {'borrower':{'name':'b2'},'amount': 3,'sponsor':{'name':'s2'}},
                {'borrower':{'name':'b1'},'amount': 1.5,'sponsor':{'name':'s1'}},
                {'borrower':{'name':'b2'},'amount': 4,'sponsor':{'name':'s3'}},
                {'borrower':{'name':'b1'},'amount': 3.5,'sponsor':{'name':'s3'}}]

    orderedBorrowers = [b3, b2, b1]
    orderedSponsors = [s3, s2, s1]

    result = deptCalculator.makeEven(orderedBorrowers, orderedSponsors, Decimal(0))
    #print(result)
    assert result == expectedResult
Пример #3
0
def test_make_even_sanity_with_dispenses():
    b1 = ('b1', {'name':'b1', 'amount': Decimal(-4)})
    b2 = ('b2', {'name':'b2', 'amount': Decimal(-6)})
    b3 = ('b3', {'name':'b3', 'amount': Decimal(-8)})
    
    s1 = ('s1', {'name':'s1', 'amount': Decimal(2.5)})
    s2 = ('s2', {'name':'s2', 'amount': Decimal(5)})
    s3 = ('s3', {'name':'s3', 'amount': Decimal(16.5)})

    expectedResult = [{'borrower':{'name':'Spende'},'amount': 6,'sponsor':{'name':'s3'}},
                {'borrower':{'name':'b3'},'amount': 5,'sponsor':{'name':'s2'}},
                {'borrower':{'name':'b2'},'amount': 2.5,'sponsor':{'name':'s1'}},
                {'borrower':{'name':'b1'},'amount': 4,'sponsor':{'name':'s3'}},
                {'borrower':{'name':'b3'},'amount': 3,'sponsor':{'name':'s3'}},
                {'borrower':{'name':'b2'},'amount': 3.5,'sponsor':{'name':'s3'}}]

    orderedBorrowers = [b3, b2, b1]
    orderedSponsors = [s3, s2, s1]

    result = deptCalculator.makeEven(orderedBorrowers, orderedSponsors, Decimal('6'))
    #print(result)
    assert result == expectedResult