Пример #1
0
def __test_bulk_cross_elasticity(original_quantity, new_quantity,
                                 original_price, new_price, expected_ced,
                                 repetition_count):

    original_quantity = np.repeat(original_quantity, repetition_count)
    new_quantity = np.repeat(new_quantity, repetition_count)
    original_price = np.repeat(original_price, repetition_count)
    new_price = np.repeat(new_price, repetition_count)

    expected_ced = np.repeat(expected_ced, repetition_count)
    ced = calculate_cross_elasticity(original_quantity, new_quantity,
                                     original_price, new_price)

    assert expected_ced == approx(ced)
Пример #2
0
def test_unrelated_cross_elasticity():
    original_quantity = new_quantity = 1000

    original_price = 20
    new_price = 30

    expected_ced = 0
    ced = calculate_cross_elasticity(original_quantity, new_quantity,
                                     original_price, new_price)

    assert expected_ced == approx(ced)

    __test_bulk_cross_elasticity(original_quantity, new_quantity,
                                 original_price, new_price, expected_ced, 100)
Пример #3
0
def test_complimentary_cross_elasticity():
    original_quantity = 1000
    new_quantity = 1100

    original_price = 100
    new_price = 80

    expected_ced = -0.4285714286
    ced = calculate_cross_elasticity(original_quantity, new_quantity,
                                     original_price, new_price)

    assert expected_ced == approx(ced)

    __test_bulk_cross_elasticity(original_quantity, new_quantity,
                                 original_price, new_price, expected_ced, 100)
Пример #4
0
def test_substitute_cross_elasticity():
    original_quantity = 200
    new_quantity = 400

    original_price = 1000
    new_price = 1050
    # (200 / 300) / (50 / 1025)
    expected_ced = 13.66666666666666
    ced = calculate_cross_elasticity(original_quantity, new_quantity,
                                     original_price, new_price)

    assert expected_ced == approx(ced)

    __test_bulk_cross_elasticity(original_quantity, new_quantity,
                                 original_price, new_price, expected_ced, 100)
Пример #5
0
def test_mismatched_arrays():
    with raises(ValueError):
        calculate_cross_elasticity(np.random.random(100), np.random.random(10),
                                   np.random.random(100),
                                   np.random.random(100))

    with raises(ValueError):
        calculate_cross_elasticity(np.random.random(100),
                                   np.random.random(100), np.random.random(10),
                                   np.random.random(100))

    with raises(ValueError):
        calculate_cross_elasticity(np.random.random(100),
                                   np.random.random(100),
                                   np.random.random(100), np.random.random(10))

    with raises(ValueError):
        calculate_cross_elasticity(np.random.random(10),
                                   np.random.random(1001),
                                   np.random.random(103), np.random.random(9))