def test_expand_1D_scalar(): x = 10.0 exp = np.array([10.0 * math.pow(1.02, i) for i in range(0, 10)]) res = Policy.expand_1D(x, inflate=True, inflation_rates=[0.02] * 10, num_years=10) npt.assert_allclose(exp, res)
def test_expand_1D_variable_rates(): x = np.array([4, 5, 9], dtype="f4") irates = [0.02, 0.02, 0.03, 0.035] exp2 = [] cur = 9.0 exp = np.array([4, 5, 9, 9 * 1.03, 9 * 1.03 * 1.035]) res = Policy.expand_1D(x, inflate=True, inflation_rates=irates, num_years=5) npt.assert_allclose(exp.astype("f4", casting="unsafe"), res)
def test_expand_1D_variable_rates(): x = np.array([4, 5, 9], dtype='f4') irates = [0.02, 0.02, 0.03, 0.035] exp2 = [] cur = 9.0 exp = np.array([4, 5, 9, 9 * 1.03, 9 * 1.03 * 1.035]) res = Policy.expand_1D(x, inflate=True, inflation_rates=irates, num_years=5) assert np.allclose(exp.astype('f4', casting='unsafe'), res)
def test_expand_1D_short_array(): x = np.array([4, 5, 9], dtype="i4") exp2 = np.array([9.0 * math.pow(1.02, i) for i in range(1, 8)]) exp1 = np.array([4, 5, 9]) exp = np.zeros(10) exp[:3] = exp1 exp[3:] = exp2 res = Policy.expand_1D(x, inflate=True, inflation_rates=[0.02] * 10, num_years=10) npt.assert_allclose(exp, res, atol=0.0, rtol=1.0e-7)
def test_expand_1D_short_array(): x = np.array([4, 5, 9], dtype='i4') exp2 = np.array([9.0 * math.pow(1.02, i) for i in range(1, 8)]) exp1 = np.array([4, 5, 9]) exp = np.zeros(10) exp[:3] = exp1 exp[3:] = exp2 res = Policy.expand_1D(x, inflate=True, inflation_rates=[0.02] * 10, num_years=10) assert np.allclose(exp.astype(x.dtype, casting='unsafe'), res)
def test_expand_1D_short_array(): x = np.array([4, 5, 9], dtype='i4') exp2 = np.array([9.0 * math.pow(1.02, i) for i in range(1, 8)]) exp1 = np.array([4, 5, 9]) exp = np.zeros(10) exp[:3] = exp1 exp[3:] = exp2 res = Policy.expand_1D(x, inflate=True, inflation_rates=[0.02] * 10, num_years=10) npt.assert_allclose(exp, res, atol=0.0, rtol=1.0E-7)
def test_expand_1D_scalar(): x = 10.0 exp = np.array([10.0 * math.pow(1.02, i) for i in range(0, 10)]) res = Policy.expand_1D(x, inflate=True, inflation_rates=[0.02] * 10, num_years=10) assert np.allclose(exp, res)