Skip to content

Commit

Permalink
issue #117 - fix unit tests - Decimal not float
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Oct 19, 2017
1 parent 085c0ca commit c6a7397
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions biweeklybudget/tests/unit/test_budget_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def setup(self):
self.cls = BudgetBalancer(self.mock_sess, self.pp, self.standing)

def test_simple(self):
type(self.standing).current_balance = 123.45
type(self.standing).current_balance = Decimal('123.45')
type(self.pp).budget_sums = PropertyMock(return_value={
1: {'remaining': 100},
2: {'remaining': 0},
Expand All @@ -168,7 +168,7 @@ def test_simple(self):
[
[1, 3, 99]
],
123.67
Decimal('123.67')
)
m_dpst.return_value = (
{1: 0, 3: -0},
Expand All @@ -177,7 +177,7 @@ def test_simple(self):
[1, 9, 1],
[9, 3, 10]
],
26.87
Decimal('26.87')
)
result = self.cls.plan()
assert result == {
Expand All @@ -199,20 +199,20 @@ def test_simple(self):
'name': 'three'
}
},
'standing_before': 123.45,
'standing_before': Decimal('123.45'),
'standing_id': 9,
'standing_name': 'standingBudget',
'standing_after': 26.87
'standing_after': Decimal('26.87')
}
assert mock_dpt.mock_calls == [
call(self.cls, to_balance, [], 123.45)
call(self.cls, to_balance, [], Decimal('123.45'))
]
assert m_dpst.mock_calls == [
call(
self.cls,
{1: 1, 3: -1},
[[1, 3, 99]],
123.67
Decimal('123.67')
)
]

Expand All @@ -239,19 +239,19 @@ def test_all_zeroed(self):
result = self.cls._do_plan_standing_txfr(
{1: 0, 2: 0, 6: 0},
[[1, 2, 3], [2, 6, 345.67]],
456
Decimal('456')
)
assert result == (
{1: 0, 2: 0, 6: 0},
[[1, 2, 3], [2, 6, 345.67]],
456
Decimal('456')
)

def test_all_positive(self):
result = self.cls._do_plan_standing_txfr(
{1: 50, 2: 0, 6: 150},
[[1, 2, 3], [2, 6, 345.67]],
234.56
Decimal('234.56')
)
assert result == (
{1: 0, 2: 0, 6: 0},
Expand All @@ -261,14 +261,14 @@ def test_all_positive(self):
[6, 9, 150],
[1, 9, 50]
],
434.56
Decimal('434.56')
)

def test_negative_with_coverage(self):
result = self.cls._do_plan_standing_txfr(
{1: -100, 2: -10, 6: 0},
[[1, 2, 3], [2, 6, 345.67]],
456.93
Decimal('456.93')
)
assert result == (
{1: 0, 2: 0, 6: 0},
Expand All @@ -278,14 +278,14 @@ def test_negative_with_coverage(self):
[9, 1, 100],
[9, 2, 10]
],
346.93
Decimal('346.93')
)

def test_negative_without_coverage(self):
result = self.cls._do_plan_standing_txfr(
{1: -60, 2: -356.78, 6: -90},
[[1, 2, 3], [2, 6, 345.67]],
456.78
Decimal('456.78')
)
assert result == (
{1: -50, 2: 0, 6: 0},
Expand All @@ -296,7 +296,7 @@ def test_negative_without_coverage(self):
[9, 6, 90],
[9, 1, 10]
],
0
Decimal('0')
)


Expand All @@ -322,70 +322,70 @@ def test_return_early_if_standing_zero(self):
result = self.cls._do_plan_transfers(
{1: 0, 2: 234, 6: -948.38},
[[1, 2, 3], [2, 6, 345.67]],
-123
Decimal('-123')
)
assert result == (
{1: 0, 2: 234, 6: -948.38},
[[1, 2, 3], [2, 6, 345.67]],
-123
Decimal('-123')
)

def test_return_early_if_all_positive(self):
result = self.cls._do_plan_transfers(
{1: 0, 2: 234, 6: 948.38},
[],
1234.56
Decimal('1234.56')
)
assert result == (
{1: 0, 2: 234, 6: 948.38},
[],
1234.56
Decimal('1234.56')
)

def test_return_early_if_all_negative(self):
result = self.cls._do_plan_transfers(
{1: 0, 2: -234, 6: -948.38},
[[1, 2, 3], [2, 6, 345.67]],
1234.56
Decimal('1234.56')
)
assert result == (
{1: 0, 2: -234, 6: -948.38},
[[1, 2, 3], [2, 6, 345.67]],
1234.56
Decimal('1234.56')
)

def test_simple_no_recurse_max_equal_min(self):
result = self.cls._do_plan_transfers(
{1: 100.55, 2: 0, 6: -100.55},
[],
1234.56
Decimal('1234.56')
)
assert result == (
{1: 0, 2: 0, 6: 0},
[[1, 6, 100.55]],
1234.56
Decimal('1234.56')
)

def test_simple_no_recurse_max_gt_min(self):
result = self.cls._do_plan_transfers(
{1: 200, 2: 0, 6: -100},
[],
1234.56
Decimal('1234.56')
)
assert result == (
{1: 100, 2: 0, 6: 0},
[[1, 6, 100]],
1234.56
Decimal('1234.56')
)

def test_simple_no_recurse_max_lt_min(self):
result = self.cls._do_plan_transfers(
{1: -200, 2: 0, 6: 100},
[],
1234.56
Decimal('1234.56')
)
assert result == (
{1: -100, 2: 0, 6: 0},
[[6, 1, 100]],
1234.56
Decimal('1234.56')
)

0 comments on commit c6a7397

Please sign in to comment.