def test_expand_xd_errors():
    """
    One of several _expand_?D tests.
    """
    dct = dict()
    with pytest.raises(ValueError):
        ParametersBase._expand_1D(dct, inflate=False, inflation_rates=[],
                                  num_years=10)
    with pytest.raises(ValueError):
        ParametersBase._expand_2D(dct, inflate=False, inflation_rates=[],
                                  num_years=10)
Example #2
0
def test_expand_1d_scalar():
    val = 10.0
    exp = np.array([val * math.pow(1.02, i) for i in range(0, 10)])
    res = ParametersBase._expand_1D(val,
                                    inflate=True,
                                    inflation_rates=[0.02] * 10,
                                    num_years=10)
    assert np.allclose(exp, res)
Example #3
0
def test_expand_1d_variable_rates():
    irates = [0.02, 0.02, 0.03, 0.035]
    ary = np.array([4, 5, 9], dtype='f4')
    res = ParametersBase._expand_1D(ary,
                                    inflate=True,
                                    inflation_rates=irates,
                                    num_years=5)
    exp = np.array([4, 5, 9, 9 * 1.03, 9 * 1.03 * 1.035])
    assert np.allclose(exp.astype('f4', casting='unsafe'), res)
def test_expand_1d_scalar():
    """
    One of several _expand_?D tests.
    """
    val = 10.0
    exp = np.array([val * math.pow(1.02, i) for i in range(0, 10)])
    res = ParametersBase._expand_1D(np.array([val]),
                                    inflate=True, inflation_rates=[0.02] * 10,
                                    num_years=10)
    assert np.allclose(exp, res, atol=0.01, rtol=0.0)
def test_expand_1d_variable_rates():
    """
    One of several _expand_?D tests.
    """
    irates = [0.02, 0.02, 0.03, 0.035]
    ary = np.array([4, 5, 9], dtype='f4')
    res = ParametersBase._expand_1D(ary, inflate=True,
                                    inflation_rates=irates, num_years=5)
    exp = np.array([4, 5, 9, 9 * 1.03, 9 * 1.03 * 1.035])
    assert np.allclose(exp, res, atol=0.01, rtol=0.0)
Example #6
0
def test_expand_1d_short_array():
    ary = 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 = ParametersBase._expand_1D(ary,
                                    inflate=True,
                                    inflation_rates=[0.02] * 10,
                                    num_years=10)
    assert np.allclose(exp, res, atol=0.0, rtol=1.0E-7)