from deepdiff import DeepDiff

from SAF.features.environment.quaternary import compute_features


def test_compute_binary_env_features_ThSb(Tb4RhInGe4_cif, TbRhInGe_elements_tuple):
    actual = compute_features(Tb4RhInGe4_cif, TbRhInGe_elements_tuple)
    expected = {
        "ENV_A_shortest_dist_count": 1,
        "ENV_B_shortest_dist_count": 2,
        "ENV_C_shortest_dist_count": 2,
        "ENV_D_shortest_dist_count": 2,
        "ENV_A_avg_shortest_dist_count": 1.75,
        "ENV_B_avg_shortest_dist_count": 2.0,
        "ENV_C_avg_shortest_dist_count": 2.0,
        "ENV_D_avg_shortest_dist_count": 1.25,
        "ENV_A_shortest_tol_dist_count": 6,
        "ENV_B_shortest_tol_dist_count": 4,
        "ENV_C_shortest_tol_dist_count": 4,
        "ENV_D_shortest_tol_dist_count": 3,
        "ENV_A_avg_shortest_dist_within_tol_count": 5.0,
        "ENV_B_avg_shortest_dist_within_tol_count": 4.0,
        "ENV_C_avg_shortest_dist_within_tol_count": 3.0,
        "ENV_D_avg_shortest_dist_within_tol_count": 1.75,
        "ENV_A_second_by_first_shortest_dist": 1.0205690778196779,
        "ENV_B_second_by_first_shortest_dist": 1.0291497975708501,
        "ENV_C_second_by_first_shortest_dist": 1.0184528034066713,
        "ENV_D_second_by_first_shortest_dist": 1.0291497975708501,
        "ENV_A_avg_second_by_first_shortest_dist": 1.0364821721769375,
        "ENV_B_avg_second_by_first_shortest_dist": 1.0291497975708501,
        "ENV_C_avg_second_by_first_shortest_dist": 1.0440696072782485,
        "ENV_D_avg_second_by_first_shortest_dist": 1.0680669343726787,
        "ENV_A_second_shortest_dist_count": 2,
        "EnV_B_second_shortest_dist_count": 1,
        "ENV_C_second_shortest_dist_count": 2,
        "ENV_D_second_shortest_dist_count": 1,
        "ENV_A_avg_second_shortest_dist_count": 2.0,
        "ENV_B_avg_second_shortest_dist_count": 1.0,
        "ENV_C_avg_second_shortest_dist_count": 2.0,
        "ENV_D_avg_second_shortest_dist_count": 1.25,
        "ENV_A_homoatomic_dist_by_shortest_dist": 1.2128899554336647,
        "ENV_B_homoatomic_dist_by_shortest_dist": 1.274493927125506,
        "ENV_C_homoatomic_dist_by_shortest_dist": 1.5131298793470547,
        "ENV_D_homoatomic_dist_by_shortest_dist": 1.0510121457489878,
        "ENV_A_avg_homoatomic_dist_by_shortest_dist": 1.215032553686275,
        "ENV_B_avg_homoatomic_dist_by_shortest_dist": 1.274493927125506,
        "ENV_C_avg_homoatomic_dist_by_shortest_dist": 1.4994220825306703,
        "ENV_D_avg_homoatomic_dist_by_shortest_dist": 1.0193165160610715,
        "ENV_A_count_at_A_shortest_dist": 0,
        "ENV_B_count_at_A_shortest_dist": 0,
        "ENV_C_count_at_A_shortest_dist": 0,
        "ENV_D_count_at_A_shortest_dist": 1,
        "ENV_A_avg_count_at_A_shortest_dist": 0.0,
        "ENV_B_avg_count_at_A_shortest_dist": 0.0,
        "ENV_C_avg_count_at_A_shortest_dist": 0.0,
        "ENV_D_avg_count_at_A_shortest_dist": 1.75,
        "ENV_A_count_at_B_shortest_dist": 0,
        "ENV_B_count_at_B_shortest_dist": 0,
        "ENV_C_count_at_B_shortest_dist": 0,
        "ENV_D_count_at_B_shortest_dist": 2,
        "ENV_A_avg_count_at_B_shortest_dist": 0.0,
        "ENV_B_avg_count_at_B_shortest_dist": 0.0,
        "ENV_C_avg_count_at_B_shortest_dist": 0.0,
        "ENV_D_avg_count_at_B_shortest_dist": 2.0,
        "ENV_A_count_at_C_shortest_dist": 0,
        "ENV_B_count_at_C_shortest_dist": 0,
        "ENV_C_count_at_C_shortest_dist": 0,
        "ENV_D_count_at_C_shortest_dist": 2,
        "ENV_A_avg_count_at_C_shortest_dist": 0.0,
        "ENV_B_avg_count_at_C_shortest_dist": 0.0,
        "ENV_C_avg_count_at_C_shortest_dist": 0.0,
        "ENV_D_avg_count_at_C_shortest_dist": 2.0,
        "ENV_A_count_at_D_shortest_dist": 0,
        "ENV_B_count_at_D_shortest_dist": 2,
        "ENV_C_count_at_D_shortest_dist": 0,
        "ENV_D_count_at_D_shortest_dist": 0,
        "ENV_A_avg_count_at_D_shortest_dist": 0.0,
        "ENV_B_avg_count_at_D_shortest_dist": 0.75,
        "ENV_C_avg_count_at_D_shortest_dist": 0.0,
        "ENV_D_avg_count_at_D_shortest_dist": 0.5,
    }
    diff = DeepDiff(actual, expected, significant_digits=3)
    assert diff == {}
