from deepdiff import DeepDiff

from CAF.features import binary


def test_generate_features(oliynyk_db):
    formula = "NdSi2"
    actual_features = binary.generate_features(formula, oliynyk_db)
    expected_features = {
        "formula": "NdSi2",
        "index_A": 1.0,
        "index_B": 2.0,
        "index_A_norm": 0.333333,
        "index_B_norm": 0.666667,
        "index_max": 2.0,
        "index_min": 1.0,
        "index_avg": 1.5,
        "atomic_weight_A+B_weighted": 200.41299999999998,
        "atomic_weight_A/B": 5.135817414680173,
        "atomic_weight_A-B": 116.1565,
        "period_A": 6,
        "period_B": 3,
        "group_A": 3,
        "group_B": 14,
        "group_A-B": -11,
        "Mendeleev_number_A": 19,
        "Mendeleev_number_B": 78,
        "Mendeleev_number_A-B": -59,
        "valencee_total_A": 6,
        "valencee_total_B": 4,
        "valencee_total_A-B": 2,
        "valencee_total_A+B": 10,
        "valencee_total_A+B_weighted": 14.0,
        "valencee_total_A+B_weighted_norm": 4.666666,
        "unpaired_electrons_A": 4,
        "unpaired_electrons_B": 2,
        "unpaired_electrons_A-B": 2,
        "unpaired_electrons_A+B": 6,
        "unpaired_electrons_A+B_weighted": 8.0,
        "unpaired_electrons_A+B_weighted_norm": 2.666666,
        "Gilman_A": 3,
        "Gilman_B": 4,
        "Gilman_A-B": -1,
        "Gilman_A+B": 7,
        "Gilman_A+B_weighted": 11.0,
        "Gilman_A+B_weighted_norm": 3.666667,
        "Z_eff_A": 3.822,
        "Z_eff_B": 2.321,
        "Z_eff_A-B": 1.501,
        "Z_eff_A/B": 1.6467040068935803,
        "Z_eff_max": 3.822,
        "Z_eff_min": 2.321,
        "Z_eff_avg": 3.0715000000000003,
        "Z_eff_A+B_weighted_norm": 2.8213328330000005,
        "ionization_energy_A": 5.525,
        "ionization_energy_B": 8.1517,
        "ionization_energy_A-B": -2.6266999999999996,
        "ionization_energy_A/B": 0.6777727345216336,
        "ionization_energy_max": 8.1517,
        "ionization_energy_min": 5.525,
        "ionization_energy_avg": 6.83835,
        "ionization_energy_A+B_weighted_norm": 7.2761342089,
        "coordination_number_A": 12,
        "coordination_number_B": 4,
        "coordination_number_A-B": 8,
        "ratio_closest_A": 0.5,
        "ratio_closest_B": 1.0,
        "ratio_closest_max": 1.0,
        "ratio_closest_min": 0.5,
        "ratio_closest_avg": 0.75,
        "polyhedron_distortion_A": 0.992,
        "polyhedron_distortion_B": 1.0,
        "polyhedron_distortion_max": 1.0,
        "polyhedron_distortion_min": 0.992,
        "polyhedron_distortion_avg": 0.996,
        "CIF_radius_A": 1.813,
        "CIF_radius_B": 1.176,
        "CIF_radius_A-B": 0.637,
        "CIF_radius_A/B": 1.5416666666666667,
        "CIF_radius_avg": 1.4945,
        "CIF_radius_A+B_weighted_norm": 1.388333121,
        "Pauling_radius_CN12_A": 1.818,
        "Pauling_radius_CN12_B": 1.316,
        "Pauling_radius_CN12_A-B": 0.502,
        "Pauling_radius_CN12_A/B": 1.3814589665653496,
        "Pauling_radius_CN12_avg": 1.5670000000000002,
        "Pauling_radius_CN12_A+B_weighted_norm": 1.388333121,
        "Pauling_EN_A": 1.14,
        "Pauling_EN_B": 1.9,
        "Pauling_EN_A-B": -0.76,
        "Pauling_EN_A/B": 0.6,
        "Pauling_EN_max": 1.9,
        "Pauling_EN_min": 1.14,
        "Pauling_EN_avg": 1.52,
        "Pauling_EN_A+B_weighted_norm": 1.64666692,
        "Martynov_Batsanov_EN_A": 1.2,
        "Martynov_Batsanov_EN_B": 1.98,
        "Martynov_Batsanov_EN_A-B": -0.78,
        "Martynov_Batsanov_EN_A/B": 0.6060606060606061,
        "Martynov_Batsanov_EN_max": 1.98,
        "Martynov_Batsanov_EN_min": 1.2,
        "Martynov_Batsanov_EN_avg": 1.5899999999999999,
        "Martynov_Batsanov_EN_A+B_weighted_norm": 1.72000026,
        "melting_point_K_A": 1289.15,
        "melting_point_K_B": 1683.15,
        "melting_point_K_A-B": -394.0,
        "melting_point_K_A/B": 0.7659150996643199,
        "melting_point_K_max": 1683.15,
        "melting_point_K_min": 1289.15,
        "melting_point_K_avg": 1486.15,
        "melting_point_K_A+B_weighted_norm": 1551.816798,
        "density_A": 7.0,
        "density_B": 2.33,
        "density_A-B": 4.67,
        "density_A/B": 3.004291845493562,
        "density_max": 7.0,
        "density_min": 2.33,
        "density_avg": 4.665,
        "density_A+B_weighted_norm": 3.88666511,
        "specific_heat_A": 0.19,
        "specific_heat_B": 0.71,
        "specific_heat_A-B": -0.52,
        "specific_heat_A/B": 0.26760563380281693,
        "specific_heat_max": 0.71,
        "specific_heat_min": 0.19,
        "specific_heat_avg": 0.44999999999999996,
        "specific_heat_A+B_weighted_norm": 0.53666684,
        "cohesive_energy_A": 3.4,
        "cohesive_energy_B": 4.63,
        "cohesive_energy_A-B": -1.23,
        "cohesive_energy_A/B": 0.734341252699784,
        "cohesive_energy_max": 4.63,
        "cohesive_energy_min": 3.4,
        "cohesive_energy_avg": 4.015,
        "cohesive_energy_A+B_weighted_norm": 4.22000041,
        "bulk_modulus_A": 31.8,
        "bulk_modulus_B": 98.0,
        "bulk_modulus_A-B": -66.2,
        "bulk_modulus_A/B": 0.32448979591836735,
        "bulk_modulus_max": 98.0,
        "bulk_modulus_min": 31.8,
        "bulk_modulus_avg": 64.9,
        "bulk_modulus_A+B_weighted_norm": 75.9333554,
    }
    diff = DeepDiff(expected_features, actual_features, significant_digits=3)
    assert diff == {}
