Skip to content

Commit 78b0f11

Browse files
committed
TEST: Parametrize tests
1 parent cd724f0 commit 78b0f11

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

tests/test_financial.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -234,39 +234,45 @@ def test_pmt_decimal_broadcast(self):
234234

235235

236236
class TestMirr:
237-
def test_mirr(self):
238-
val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000]
239-
assert_almost_equal(npf.mirr(val, 0.08, 0.055), 0.0666, 4)
240-
241-
val = [-120000, 39000, 30000, 21000, 37000, 46000]
242-
assert_almost_equal(npf.mirr(val, 0.10, 0.12), 0.126094, 6)
243-
244-
val = [100, 200, -50, 300, -200]
245-
assert_almost_equal(npf.mirr(val, 0.05, 0.06), 0.3428, 4)
237+
@pytest.mark.parametrize("values,finance_rate,reinvest_rate,expected", [
238+
([-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000], 0.08, 0.055, 0.0666),
239+
([-120000, 39000, 30000, 21000, 37000, 46000], 0.10, 0.12, 0.126094),
240+
([100, 200, -50, 300, -200], 0.05, 0.06, 0.3428),
241+
([39000, 30000, 21000, 37000, 46000], 0.10, 0.12, None)
242+
])
243+
def test_mirr(self, values, finance_rate, reinvest_rate, expected):
244+
result = npf.mirr(values, finance_rate, reinvest_rate)
246245

247-
val = [39000, 30000, 21000, 37000, 46000]
248-
assert_(numpy.isnan(npf.mirr(val, 0.10, 0.12)))
249-
250-
def test_mirr_decimal(self):
251-
val = [Decimal('-4500'), Decimal('-800'), Decimal('800'),
252-
Decimal('800'), Decimal('600'), Decimal('600'), Decimal('800'),
253-
Decimal('800'), Decimal('700'), Decimal('3000')]
254-
assert_equal(npf.mirr(val, Decimal('0.08'), Decimal('0.055')),
255-
Decimal('0.066597175031553548874239618'))
256-
257-
val = [Decimal('-120000'), Decimal('39000'), Decimal('30000'),
258-
Decimal('21000'), Decimal('37000'), Decimal('46000')]
259-
assert_equal(npf.mirr(val, Decimal('0.10'), Decimal('0.12')),
260-
Decimal('0.126094130365905145828421880'))
261-
262-
val = [Decimal('100'), Decimal('200'), Decimal('-50'),
263-
Decimal('300'), Decimal('-200')]
264-
assert_equal(npf.mirr(val, Decimal('0.05'), Decimal('0.06')),
265-
Decimal('0.342823387842176663647819868'))
266-
267-
val = [Decimal('39000'), Decimal('30000'), Decimal('21000'),
268-
Decimal('37000'), Decimal('46000')]
269-
assert_(numpy.isnan(npf.mirr(val, Decimal('0.10'), Decimal('0.12'))))
246+
if expected:
247+
decimal_part_len = len(str(expected).split('.')[1])
248+
assert_almost_equal(result, expected, decimal_part_len)
249+
else:
250+
assert_(numpy.isnan(result))
251+
252+
@pytest.mark.parametrize(
253+
"args, expected",
254+
[
255+
({'values': [Decimal('-4500'), Decimal('-800'), Decimal('800'), Decimal('800'),
256+
Decimal('600'), Decimal('600'), Decimal('800'), Decimal('800'),
257+
Decimal('700'), Decimal('3000')],
258+
'finance_rate': Decimal('0.08'), 'reinvest_rate': Decimal('0.055')},
259+
Decimal('0.066597175031553548874239618')),
260+
({'values': [Decimal('-120000'), Decimal('39000'), Decimal('30000'), Decimal('21000'),
261+
Decimal('37000'), Decimal('46000')],
262+
'finance_rate': Decimal('0.10'), 'reinvest_rate': Decimal('0.12')},
263+
Decimal('0.126094130365905145828421880')),
264+
({'values': [Decimal('100'), Decimal('200'), Decimal('-50'), Decimal('300'), Decimal('-200')],
265+
'finance_rate': Decimal('0.05'), 'reinvest_rate': Decimal('0.06')},
266+
Decimal('0.342823387842176663647819868')),
267+
({'values': [Decimal('39000'), Decimal('30000'), Decimal('21000'), Decimal('37000'),
268+
Decimal('46000')],
269+
'finance_rate': Decimal('0.10'), 'reinvest_rate': Decimal('0.12')},
270+
numpy.nan),
271+
],
272+
)
273+
def test_mirr_decimal(self, args, expected):
274+
result = npf.mirr(**args)
275+
assert_equal(result, expected)
270276

271277
def test_mirr_no_real_solution_exception(self):
272278
# Test that if there is no solution because all the cashflows

0 commit comments

Comments
 (0)