Skip to content

Commit 348b63e

Browse files
committed
TST: Move Pmt tests into own class
1 parent f9c948e commit 348b63e

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

numpy_financial/tests/test_financial.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,48 +48,6 @@ def test_pv_decimal(self):
4848
Decimal('0')),
4949
Decimal('-127128.1709461939327295222005'))
5050

51-
def test_pmt(self):
52-
res = npf.pmt(0.08 / 12, 5 * 12, 15000)
53-
tgt = -304.145914
54-
assert_allclose(res, tgt)
55-
# Test the edge case where rate == 0.0
56-
res = npf.pmt(0.0, 5 * 12, 15000)
57-
tgt = -250.0
58-
assert_allclose(res, tgt)
59-
# Test the case where we use broadcast and
60-
# the arguments passed in are arrays.
61-
res = npf.pmt([[0.0, 0.8], [0.3, 0.8]], [12, 3], [2000, 20000])
62-
tgt = numpy.array([[-166.66667, -19311.258], [-626.90814, -19311.258]])
63-
assert_allclose(res, tgt)
64-
65-
def test_pmt_decimal(self):
66-
res = npf.pmt(Decimal('0.08') / Decimal('12'), 5 * 12, 15000)
67-
tgt = Decimal('-304.1459143262052370338701494')
68-
assert_equal(res, tgt)
69-
# Test the edge case where rate == 0.0
70-
res = npf.pmt(Decimal('0'), Decimal('60'), Decimal('15000'))
71-
tgt = -250
72-
assert_equal(res, tgt)
73-
74-
# Test the case where we use broadcast and
75-
# the arguments passed in are arrays.
76-
res = npf.pmt([[Decimal('0'), Decimal('0.8')],
77-
[Decimal('0.3'), Decimal('0.8')]],
78-
[Decimal('12'), Decimal('3')],
79-
[Decimal('2000'), Decimal('20000')])
80-
tgt = numpy.array([[Decimal('-166.6666666666666666666666667'),
81-
Decimal('-19311.25827814569536423841060')],
82-
[Decimal('-626.9081401700757748402586600'),
83-
Decimal('-19311.25827814569536423841060')]])
84-
85-
# Cannot use the `assert_allclose` because it uses isfinite under
86-
# the covers which does not support the Decimal type
87-
# See issue: https://github.com/numpy/numpy/issues/9954
88-
assert_equal(res[0][0], tgt[0][0])
89-
assert_equal(res[0][1], tgt[0][1])
90-
assert_equal(res[1][0], tgt[1][0])
91-
assert_equal(res[1][1], tgt[1][1])
92-
9351
def test_npv(self):
9452
assert_almost_equal(
9553
npf.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
@@ -172,6 +130,50 @@ def test_decimal_with_when(self):
172130
Decimal('0'), 'end'))
173131

174132

133+
class TestPmt:
134+
def test_pmt(self):
135+
res = npf.pmt(0.08 / 12, 5 * 12, 15000)
136+
tgt = -304.145914
137+
assert_allclose(res, tgt)
138+
# Test the edge case where rate == 0.0
139+
res = npf.pmt(0.0, 5 * 12, 15000)
140+
tgt = -250.0
141+
assert_allclose(res, tgt)
142+
# Test the case where we use broadcast and
143+
# the arguments passed in are arrays.
144+
res = npf.pmt([[0.0, 0.8], [0.3, 0.8]], [12, 3], [2000, 20000])
145+
tgt = numpy.array([[-166.66667, -19311.258], [-626.90814, -19311.258]])
146+
assert_allclose(res, tgt)
147+
148+
def test_pmt_decimal(self):
149+
res = npf.pmt(Decimal('0.08') / Decimal('12'), 5 * 12, 15000)
150+
tgt = Decimal('-304.1459143262052370338701494')
151+
assert_equal(res, tgt)
152+
# Test the edge case where rate == 0.0
153+
res = npf.pmt(Decimal('0'), Decimal('60'), Decimal('15000'))
154+
tgt = -250
155+
assert_equal(res, tgt)
156+
157+
# Test the case where we use broadcast and
158+
# the arguments passed in are arrays.
159+
res = npf.pmt([[Decimal('0'), Decimal('0.8')],
160+
[Decimal('0.3'), Decimal('0.8')]],
161+
[Decimal('12'), Decimal('3')],
162+
[Decimal('2000'), Decimal('20000')])
163+
tgt = numpy.array([[Decimal('-166.6666666666666666666666667'),
164+
Decimal('-19311.25827814569536423841060')],
165+
[Decimal('-626.9081401700757748402586600'),
166+
Decimal('-19311.25827814569536423841060')]])
167+
168+
# Cannot use the `assert_allclose` because it uses isfinite under
169+
# the covers which does not support the Decimal type
170+
# See issue: https://github.com/numpy/numpy/issues/9954
171+
assert_equal(res[0][0], tgt[0][0])
172+
assert_equal(res[0][1], tgt[0][1])
173+
assert_equal(res[1][0], tgt[1][0])
174+
assert_equal(res[1][1], tgt[1][1])
175+
176+
175177
class TestMirr:
176178
def test_mirr(self):
177179
val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000]

0 commit comments

Comments
 (0)