import pandas as pd
import math
from .power import main


def test_int_int():
    assert main(base=2, exponent=4)["power"] == 16


def test_series_int():
    assert main(
        base=pd.Series(
            {
                "2019-08-01T15:20:12": 4,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 2,
                "2019-08-05T12:00:34": 8,
            }
        ),
        exponent=-1,
    )["power"].equals(
        pd.Series(
            {
                "2019-08-01T15:20:12": 0.25,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 0.5,
                "2019-08-05T12:00:34": 0.125,
            }
        )
    )


def test_series_series():
    assert main(
        base=pd.Series(
            {
                "2019-08-01T15:20:12": 1,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 2,
                "2019-08-05T12:00:34": 4,
            }
        ),
        exponent=pd.Series(
            {
                "2019-08-01T15:20:12": 2,
                "2019-08-01T15:44:12": 4,
                "2019-08-03T16:20:15": 0,
                "2019-08-05T12:00:34": 2,
            }
        ),
    )["power"].equals(
        pd.Series(
            {
                "2019-08-01T15:20:12": 1,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 1,
                "2019-08-05T12:00:34": 16,
            }
        )
    )


def test_df_df():
    assert main(
        base=pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 3,
                    "2019-08-01T15:44:12": 7,
                    "2019-08-03T16:20:15": 0,
                    "2019-08-05T12:00:34": 2,
                },
                "b": {
                    "2019-08-01T15:20:12": 0,
                    "2019-08-01T15:44:12": 4,
                    "2019-08-03T16:20:15": 5,
                    "2019-08-05T12:00:34": 7,
                },
            }
        ),
        exponent=pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 1,
                    "2019-08-01T15:44:12": 2,
                    "2019-08-03T16:20:15": 3,
                    "2019-08-05T12:00:34": 2,
                },
                "b": {
                    "2019-08-01T15:20:12": 1,
                    "2019-08-01T15:44:12": 3,
                    "2019-08-03T16:20:15": 2,
                    "2019-08-05T12:00:34": 0,
                },
            }
        ),
    )["power"].equals(
        pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 3,
                    "2019-08-01T15:44:12": 49,
                    "2019-08-03T16:20:15": 0,
                    "2019-08-05T12:00:34": 4,
                },
                "b": {
                    "2019-08-01T15:20:12": 0,
                    "2019-08-01T15:44:12": 64,
                    "2019-08-03T16:20:15": 25,
                    "2019-08-05T12:00:34": 1,
                },
            }
        )
    )


def test_empty_series_series():
    assert (
        math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][0]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][1]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][2]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][3]
        )
        and main(
            base=pd.Series(dtype=float),
            exponent=pd.Series(
                {
                    "2019-08-01T15:20:12": 1.0,
                    "2019-08-01T15:44:12": 27,
                    "2019-08-03T16:20:15": 3.6,
                    "2019-08-05T12:00:34": 17,
                }
            ),
        )["power"].index.all(
            [
                "2019-08-01T15:20:12",
                "2019-08-01T15:44:12",
                "2019-08-03T16:20:15",
                "2019-08-05T12:00:34",
            ]
        )
    )


import pandas as pd
import math
from .power import main


def test_int_int():
    assert main(base=2, exponent=4)["power"] == 16


def test_series_int():
    assert main(
        base=pd.Series(
            {
                "2019-08-01T15:20:12": 4,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 2,
                "2019-08-05T12:00:34": 8,
            }
        ),
        exponent=-1,
    )["power"].equals(
        pd.Series(
            {
                "2019-08-01T15:20:12": 0.25,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 0.5,
                "2019-08-05T12:00:34": 0.125,
            }
        )
    )


def test_series_series():
    assert main(
        base=pd.Series(
            {
                "2019-08-01T15:20:12": 1,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 2,
                "2019-08-05T12:00:34": 4,
            }
        ),
        exponent=pd.Series(
            {
                "2019-08-01T15:20:12": 2,
                "2019-08-01T15:44:12": 4,
                "2019-08-03T16:20:15": 0,
                "2019-08-05T12:00:34": 2,
            }
        ),
    )["power"].equals(
        pd.Series(
            {
                "2019-08-01T15:20:12": 1,
                "2019-08-01T15:44:12": None,
                "2019-08-03T16:20:15": 1,
                "2019-08-05T12:00:34": 16,
            }
        )
    )


def test_df_df():
    assert main(
        base=pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 3,
                    "2019-08-01T15:44:12": 7,
                    "2019-08-03T16:20:15": 0,
                    "2019-08-05T12:00:34": 2,
                },
                "b": {
                    "2019-08-01T15:20:12": 0,
                    "2019-08-01T15:44:12": 4,
                    "2019-08-03T16:20:15": 5,
                    "2019-08-05T12:00:34": 7,
                },
            }
        ),
        exponent=pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 1,
                    "2019-08-01T15:44:12": 2,
                    "2019-08-03T16:20:15": 3,
                    "2019-08-05T12:00:34": 2,
                },
                "b": {
                    "2019-08-01T15:20:12": 1,
                    "2019-08-01T15:44:12": 3,
                    "2019-08-03T16:20:15": 2,
                    "2019-08-05T12:00:34": 0,
                },
            }
        ),
    )["power"].equals(
        pd.DataFrame(
            {
                "a": {
                    "2019-08-01T15:20:12": 3,
                    "2019-08-01T15:44:12": 49,
                    "2019-08-03T16:20:15": 0,
                    "2019-08-05T12:00:34": 4,
                },
                "b": {
                    "2019-08-01T15:20:12": 0,
                    "2019-08-01T15:44:12": 64,
                    "2019-08-03T16:20:15": 25,
                    "2019-08-05T12:00:34": 1,
                },
            }
        )
    )


def test_empty_series_series():
    assert (
        math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][0]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][1]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][2]
        )
        and math.isnan(
            main(
                base=pd.Series(dtype=float),
                exponent=pd.Series(
                    {
                        "2019-08-01T15:20:12": 1.0,
                        "2019-08-01T15:44:12": 27,
                        "2019-08-03T16:20:15": 3.6,
                        "2019-08-05T12:00:34": 17,
                    }
                ),
            )["power"][3]
        )
        and main(
            base=pd.Series(dtype=float),
            exponent=pd.Series(
                {
                    "2019-08-01T15:20:12": 1.0,
                    "2019-08-01T15:44:12": 27,
                    "2019-08-03T16:20:15": 3.6,
                    "2019-08-05T12:00:34": 17,
                }
            ),
        )["power"].index.all(
            [
                "2019-08-01T15:20:12",
                "2019-08-01T15:44:12",
                "2019-08-03T16:20:15",
                "2019-08-05T12:00:34",
            ]
        )
    )

