from rocketpy import utilities
import numpy as np


def test_compute_CdS_from_drop_test():
    assert (
        utilities.compute_CdS_from_drop_test(31.064, 18, 1.0476) == 0.3492311157844522
    )


def test_create_dispersion_dictionary():
    """Test if the function returns a dictionary with the correct keys.
    It reads the keys from the dictionary generated by the utilities function
    and compares them to the expected.
    Be careful if you change the "fixtures/dispersion/Valetudo_inputs.csv" file.
    """

    returned_dict = utilities.create_dispersion_dictionary(
        "tests/fixtures/dispersion/Valetudo_inputs.csv"
    )

    test_array = np.genfromtxt(
        "tests/fixtures/dispersion/Valetudo_inputs.csv",
        usecols=(1, 2, 3),
        skip_header=1,
        delimiter=";",
        dtype=str,
    )
    test_dict = dict()
    for row in test_array:
        if row[0] != "":
            if row[2] == "":
                try:
                    test_dict[row[0].strip()] = float(row[1])
                except:
                    test_dict[row[0].strip()] = eval(row[1])
            else:
                try:
                    test_dict[row[0].strip()] = (float(row[1]), float(row[2]))
                except:
                    test_dict[row[0].strip()] = ""
    assert returned_dict == test_dict
