import numpy as np
import pytest
from backend.ml_models.AnnualBillSavings import AnnualBillSavings

appliance_consumption_cases = [
    {
        "total_floor_area": 13.9,
        "n_occupants": 1,
        "consumption": 718.4795859263703
    },
    {
        "total_floor_area": 20,
        "n_occupants": 1.0306381042556767,
        "consumption": 865.2316409517844
    },
    {
        "total_floor_area": 30,
        "n_occupants": 1.1731577598127325,
        "consumption": 1113.5965321501362
    },
    {
        "total_floor_area": 50,
        "n_occupants": 1.6901008890848956,
        "consumption": 1683.31305074609
    },
    {
        "total_floor_area": 75,
        "n_occupants": 2.361158387531988,
        "consumption": 2386.2935599981865
    },
    {
        "total_floor_area": 100,
        "n_occupants": 2.739525875076067,
        "consumption": 2931.6076153011486
    },
    {
        "total_floor_area": 125,
        "n_occupants": 2.8807344137165405,
        "consumption": 3335.143110751552
    },
    {
        "total_floor_area": 150,
        "n_occupants": 2.934188599837662,
        "consumption": 3666.3228057866513
    },
    {
        "total_floor_area": 200,
        "n_occupants": 3.001920087128373,
        "consumption": 4244.625403339813
    },
    {
        "total_floor_area": 300,
        "n_occupants": 3.1319299999993095,
        "consumption": 5243.086106676302
    },
    {
        "total_floor_area": 500,
        "n_occupants": 3.39193,
        "consumption": 6927.400500420533
    },
    {
        "total_floor_area": 1000,
        "n_occupants": 4.04193,
        "consumption": 10434.755635642652
    }
]


class TestAnnualBillSavings:

    @pytest.mark.parametrize(
        "test_case",
        appliance_consumption_cases
    )
    def test_appliance_estimation(self, test_case):
        n_occupants = AnnualBillSavings.calculate_occupants(test_case["total_floor_area"])
        assert np.isclose(n_occupants, test_case["n_occupants"])

        appliance_consumption = AnnualBillSavings.estimate_electrical_appliances(
            n_occupants, test_case["total_floor_area"]
        )
        assert np.isclose(appliance_consumption, test_case["consumption"])
