Beispiel #1
0
def test_linear_utility():
    """Calculate the linear_utility and checks that it is not none."""
    currency_holdings = {"FET": 100}
    utility_params = {"good_id": 20.0}
    exchange_params = {"FET": 10.0}
    tx_fee = 9
    preferences = Preferences(
        utility_params_by_good_id=utility_params,
        exchange_params_by_currency_id=exchange_params,
        tx_fee=tx_fee,
    )
    linear_utility = preferences.linear_utility(
        amount_by_currency_id=currency_holdings)
    assert linear_utility is not None, "Linear utility must not be none."
Beispiel #2
0
def test_utility():
    """Calculate the score."""
    utility_params = {"good_id": 20.0}
    exchange_params = {"FET": 10.0}
    currency_holdings = {"FET": 100}
    good_holdings = {"good_id": 2}
    tx_fee = 9
    preferences = Preferences(
        utility_params_by_good_id=utility_params,
        exchange_params_by_currency_id=exchange_params,
        tx_fee=tx_fee,
    )
    score = preferences.utility(
        quantities_by_good_id=good_holdings,
        amount_by_currency_id=currency_holdings,
    )
    linear_utility = preferences.linear_utility(
        amount_by_currency_id=currency_holdings)
    log_utility = preferences.logarithmic_utility(
        quantities_by_good_id=good_holdings)
    assert (
        score == log_utility + linear_utility
    ), "The score must be equal to the sum of log_utility and linear_utility."