diff --git a/app/pe/moys/pe_rcstag.py b/app/pe/moys/pe_rcstag.py index f7cb4d5b..1ff960cc 100644 --- a/app/pe/moys/pe_rcstag.py +++ b/app/pe/moys/pe_rcstag.py @@ -408,7 +408,7 @@ def compute_moyennes_par_RCS( coeffs_rcue_cube: coeffs des RCUE appliqués dans les moyennes de RCS inscr_mask: inscriptions aux compétences ndarray (etuds_sorted x UEs|compétences x sxtags), - des 0 et des 1 + des 1.0 (si inscrit) et des NaN (si non inscrit) Returns: Un DataFrame avec pour columns les moyennes par tags, et pour rows les etudid diff --git a/tests/unit/test_pe.py b/tests/unit/test_pe.py index 81b4d9c0..23c9779f 100644 --- a/tests/unit/test_pe.py +++ b/tests/unit/test_pe.py @@ -2,6 +2,8 @@ Test calcul moyennes pour les poursuites d'études """ import numpy as np +import pytest + from tests.unit import setup from app import db @@ -9,6 +11,94 @@ from app import db import app.pe.moys.pe_rcstag as pe_rcstag -def test_compute_moyennes_par_RCS: - """Test""" - pass \ No newline at end of file +@pytest.mark.parametrize( + "notes_S1, notes_S2, coeffs_S1, coeffs_S2, " + "coeffs_rcues_S1, coeffs_rcues_S2, inscr_S1, inscr_S2," + "moyenne, coeffs_aggreges", + [ + pytest.param( + [17.0, 15.0, 12.0], + [16.0, 14.0, 13.0], # notes + [1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], # coeffs moy gen + [2.0, 4.0, 6.0], + [8.0, 10.0, 12.0], # coeffs recus + [1.0, 1.0, 1.0], + [1.0, 1.0, 1.0], # inscr + [ + (17.0 * 2.0 + 16.0 * 8.0) / (2.0 + 8.0), + (15.0 * 4.0 + 14.0 * 10.0) / (4.0 + 10.0), + (12.0 * 6.0 + 13.0 * 12.0) / (6.0 + 12.0), + ], + [1.0 + 4.0, 2.0 + 5.0, 3.0 + 6.0], + id="etudiant_parfait", + ), + pytest.param( + [17.0, 15.0, 12.0], + [16.0, 14.0, 13.0], # notes + [1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], # coeffs moy gen + [2.0, 4.0, 6.0], + [8.0, 10.0, 12.0], # coeffs recus + [np.nan, 1.0, np.nan], + [1.0, np.nan, np.nan], # inscr + [ + (16.0 * 8.0) / (8.0), + (15.0 * 4.0) / (4.0), + np.nan, + ], + [4.0, 2.0, np.nan], + id="etudiant_non_inscrit", + ), + pytest.param( + [0.0, 15.0, 0.0], + [0.0, 0.0, 0.0], # notes + [1.0, 2.0, 3.0], + [4.0, 5.0, 6.0], # coeffs moy gen + [2.0, 4.0, 6.0], + [8.0, 10.0, 12.0], # coeffs recus + [np.nan, 1.0, 1.0], + [1.0, np.nan, 1.0], # inscr + [0.0, 15.0, 0.0], + [4.0, 2.0, 3.0 + 6.0], + id="etudiant_avec_0", + ), + ], +) +def test_compute_moyennes_par_RCS( + notes_S1, + notes_S2, + coeffs_S1, + coeffs_S2, + coeffs_rcues_S1, + coeffs_rcues_S2, + inscr_S1, + inscr_S2, + moyenne, + coeffs_aggreges, +): + """Test de pe_rcstag.compute_moyennes_par_RCS""" + notes_cube = np.stack([np.array([notes_S1]), np.array([notes_S2])], axis=-1) + # Vérifie les dimensions + dim1, dim2, dim3 = notes_cube.shape + assert dim1 == 1, "La dim 0 doit être le nombre d'étudiants" + assert dim2 == 3, "La dim 1 doit être le nombre d'UEs/Compétences" + assert dim3 == 2, "La dim 2 doit être le nombre de semestres" + + coeffs_cube = np.stack([np.array([coeffs_S1]), np.array([coeffs_S2])], axis=-1) + coeffs_rcue_cube = np.stack( + [np.array([coeffs_rcues_S1]), np.array([coeffs_rcues_S2])], axis=-1 + ) + inscr_cube = np.stack([np.array([inscr_S1]), np.array([inscr_S2])], axis=-1) + moys, coeffs = pe_rcstag.compute_moyennes_par_RCS( + notes_cube, coeffs_cube, coeffs_rcue_cube, inscr_cube + ) + + moy_resultat = np.array([moyenne]) + assert ( + (moys == moy_resultat) | (np.isnan(moys) & np.isnan(moy_resultat)) + ).all(), "Moyenne erronée" + coeffs_resultat = np.array([coeffs_aggreges]) + assert ( + (coeffs == coeffs_resultat) | (np.isnan(coeffs) & np.isnan(coeffs_resultat)) + ).all(), "Coeffs (pour moyenne générale sur toutes les UE) erronés"