Skip to content

Commit 7916656

Browse files
committed
more tests
1 parent 4615306 commit 7916656

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

ogcore/pensions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,15 @@ def deriv_DB(w, e, per_rmn, p):
445445
Change in DB pension benefits for another unit of labor supply
446446
"""
447447

448-
if per_rmn < (p.S - p.S_ret + 1):
448+
if per_rmn < (p.S - p.retire + 1):
449449
d_theta = np.zeros(p.S)
450450
else:
451-
d_theta_empty = np.zeros(p.S)
452451
d_theta = deriv_DB_loop(
453452
w,
454453
e,
455454
p.S,
456-
p.S_ret,
455+
p.retire,
457456
per_rmn,
458-
p.g_y,
459-
d_theta_empty,
460457
p.last_career_yrs,
461458
p.rep_rate_py,
462459
p.yr_contr,

tests/test_pensions.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,54 @@ def test_deriv_PS_loop(args, deriv_PS_loop_expected):
222222
)
223223

224224
assert np.allclose(deriv_PS_loop, deriv_PS_loop_expected)
225+
226+
227+
#############non-zero d_theta: case 1############
228+
p = Specifications()
229+
p.S = 7
230+
p.retire = 4
231+
p.last_career_yrs = 3
232+
p.yr_contr = p.retire
233+
p.rep_rate_py = 0.2
234+
p.g_y = 0.03
235+
n_ddb1 = np.array([0.4, 0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
236+
w_ddb1 = np.array([1.2, 1.1, 1.21, 1, 1.01, 0.99, 0.8])
237+
e_ddb1 = np.array([1.1, 1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
238+
per_rmn = n_ddb1.shape[0]
239+
d_theta_empty = np.zeros_like(per_rmn)
240+
deriv_DB_expected1 = np.array(
241+
[0.352, 0.3256, 0.2904, 0.232, 0.0, 0.0, 0.0])
242+
args_ddb1 = (w_ddb1, e_ddb1, per_rmn, p)
243+
244+
#############non-zero d_theta: case 2############
245+
p2 = Specifications()
246+
p2.S = 7
247+
p2.retire = 5
248+
p2.last_career_yrs = 2
249+
p2.yr_contr = p2.retire
250+
p2.rep_rate_py = 0.2
251+
p2.g_y = 0.03
252+
n_ddb2 = np.array([0.45, 0.4, 0.42, 0.3, 0.2, 0.2])
253+
w_ddb1 = np.array([1.1, 1.21, 1, 1.01, 0.99, 0.8])
254+
e_ddb1 = np.array([1.11, 0.9, 0.87, 0.87, 0.7, 0.6])
255+
per_rmn = n_ddb2.shape[0]
256+
d_theta_empty = np.zeros_like(per_rmn)
257+
deriv_DB_expected2 = np.array(
258+
[0.6105, 0.5445, 0.435, 0.43935, 0.0, 0.0])
259+
args_ddb2 = (w_ddb1, e_ddb1, per_rmn, p2)
260+
261+
test_data = [(args_ddb1, deriv_DB_expected1),
262+
(args_ddb2, deriv_DB_expected2)]
263+
264+
265+
@pytest.mark.parametrize('args,deriv_DB_expected', test_data,
266+
ids=['non-zero d_theta: case 1',
267+
'non-zero d_theta: case 2'])
268+
def test_deriv_DB(args, deriv_DB_expected):
269+
"""
270+
Test of the pensions.deriv_DB() function.
271+
"""
272+
(w, e, per_rmn, p) = args
273+
deriv_DB = pensions.deriv_DB(w, e, per_rmn, p)
274+
275+
assert (np.allclose(deriv_DB, deriv_DB_expected))

0 commit comments

Comments
 (0)