Skip to content

Commit 196184c

Browse files
committed
TST: Move rate tests into own class
1 parent ce1a1df commit 196184c

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

numpy_financial/tests/test_financial.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,6 @@
1313

1414

1515
class TestFinancial(object):
16-
def test_rate(self):
17-
assert_almost_equal(npf.rate(10, 0, -3500, 10000), 0.1107, 4)
18-
19-
@pytest.mark.parametrize('number_type', [Decimal, float])
20-
@pytest.mark.parametrize('when', [0, 1, 'end', 'begin'])
21-
def test_rate_with_infeasible_solution(self, number_type, when):
22-
"""
23-
Test when no feasible rate can be found.
24-
25-
Rate will return NaN, if the Newton Raphson method cannot find a
26-
feasible rate within the required tolerance or number of iterations.
27-
This can occur if both `pmt` and `pv` have the same sign, as it is
28-
impossible to repay a loan by making further withdrawls.
29-
"""
30-
result = npf.rate(number_type(12.0),
31-
number_type(400.0),
32-
number_type(10000.0),
33-
number_type(5000.0),
34-
when=when)
35-
is_nan = Decimal.is_nan if number_type == Decimal else numpy.isnan
36-
assert is_nan(result)
37-
38-
def test_rate_decimal(self):
39-
rate = npf.rate(Decimal('10'), Decimal('0'), Decimal('-3500'),
40-
Decimal('10000'))
41-
assert_equal(Decimal('0.1106908537142689284704528100'), rate)
42-
4316
def test_pv(self):
4417
assert_almost_equal(npf.pv(0.07, 20, 12000, 0), -127128.17, 2)
4518

@@ -120,6 +93,35 @@ def test_decimal_with_when(self):
12093
Decimal('0'), 'end'))
12194

12295

96+
class TestRate:
97+
def test_rate(self):
98+
assert_almost_equal(npf.rate(10, 0, -3500, 10000), 0.1107, 4)
99+
100+
@pytest.mark.parametrize('number_type', [Decimal, float])
101+
@pytest.mark.parametrize('when', [0, 1, 'end', 'begin'])
102+
def test_rate_with_infeasible_solution(self, number_type, when):
103+
"""
104+
Test when no feasible rate can be found.
105+
106+
Rate will return NaN, if the Newton Raphson method cannot find a
107+
feasible rate within the required tolerance or number of iterations.
108+
This can occur if both `pmt` and `pv` have the same sign, as it is
109+
impossible to repay a loan by making further withdrawls.
110+
"""
111+
result = npf.rate(number_type(12.0),
112+
number_type(400.0),
113+
number_type(10000.0),
114+
number_type(5000.0),
115+
when=when)
116+
is_nan = Decimal.is_nan if number_type == Decimal else numpy.isnan
117+
assert is_nan(result)
118+
119+
def test_rate_decimal(self):
120+
rate = npf.rate(Decimal('10'), Decimal('0'), Decimal('-3500'),
121+
Decimal('10000'))
122+
assert_equal(Decimal('0.1106908537142689284704528100'), rate)
123+
124+
123125
class TestNpv:
124126
def test_npv(self):
125127
assert_almost_equal(

0 commit comments

Comments
 (0)