From 780a7c53af0101959f4c9721fd38560b18d650c5 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sun, 13 Nov 2016 16:14:32 +0300 Subject: [PATCH] tests for df_marks_manip --- notes_tools/df_marks_manip.py | 13 ++++--- notes_tools/test/test_df_marks_manip.py | 47 ++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/notes_tools/df_marks_manip.py b/notes_tools/df_marks_manip.py index d472b59..cb68f5f 100644 --- a/notes_tools/df_marks_manip.py +++ b/notes_tools/df_marks_manip.py @@ -8,15 +8,18 @@ from math import ceil # Values manipulations def round_half_point(val): - try: - return 0.5 * ceil(2.0 * val) - except ValueError: - return val + return 0.5 * ceil(2.0 * val) + #try: + # return 0.5 * ceil(2.0 * val) + #except ValueError: + # return val latex_caract = ["\\NoRep", "\\RepZ", "\\RepU", "\\RepD", "\\RepT"] def note_to_rep(x): r""" Transform a Note to the latex caracter + :param x: dictionnary with "Niveau" and "Note" keys + >>> d = {"Eleve":["E1"]*6 + ["E2"]*6, ... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2, ... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"], @@ -43,6 +46,8 @@ def note_to_rep(x): def note_to_mark(x): """ Compute the mark when it is a "Nivea" note + :param x: dictionnary with "Niveau", "Note" and "Bareme" keys + >>> d = {"Eleve":["E1"]*6 + ["E2"]*6, ... "Nom": ["N1"]*4+["N2"]*2 + ["N1"]*4+["N2"]*2, ... "Exercice":["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"] + ["Ex1"]*2+["Ex2"]*2+["Ex1"]+["Ex2"], diff --git a/notes_tools/test/test_df_marks_manip.py b/notes_tools/test/test_df_marks_manip.py index 0b81053..b2d7985 100644 --- a/notes_tools/test/test_df_marks_manip.py +++ b/notes_tools/test/test_df_marks_manip.py @@ -3,12 +3,57 @@ from notes_tools import df_marks_manip +import pandas -# TODO: faire des tests unitaire |mar. nov. 8 11:20:57 EAT 2016 +def test_round_half_point(): + assert df_marks_manip.round_half_point(2) == 2 + assert df_marks_manip.round_half_point(2.1) == 2.5 + assert df_marks_manip.round_half_point(2.4) == 2.5 + assert df_marks_manip.round_half_point(2.6) == 3 + assert df_marks_manip.round_half_point(2.9) == 3 + +def test_note_to_rep(): + d = {"Niveau": 1, "Note": 0} + assert df_marks_manip.note_to_rep(d) == "\\RepZ" + + d = {"Niveau": 1, "Note": 1} + assert df_marks_manip.note_to_rep(d) == "\\RepU" + + d = {"Niveau": 1, "Note": 2} + assert df_marks_manip.note_to_rep(d) == "\\RepD" + + d = {"Niveau": 1, "Note": 3} + assert df_marks_manip.note_to_rep(d) == "\\RepT" + + d = {"Niveau": 1, "Note": None} + assert df_marks_manip.note_to_rep(d) == "\\NoRep" + + d = {"Niveau": 1, "Note": pandas.np.nan} + assert df_marks_manip.note_to_rep(d) == "\\NoRep" + + d = {"Niveau": 0, "Note": "plop"} + assert df_marks_manip.note_to_rep(d) == "plop" + + d = {"Niveau": 0, "Note": 1} + assert df_marks_manip.note_to_rep(d) == 1 +def test_note_to_mark(): + d = {"Niveau": 1, "Note": 0, "Bareme": 6} + assert df_marks_manip.note_to_mark(d) == 6/3*0 + d = {"Niveau": 1, "Note": 1, "Bareme": 6} + assert df_marks_manip.note_to_mark(d) == 6/3*1 + + d = {"Niveau": 1, "Note": 2, "Bareme": 6} + assert df_marks_manip.note_to_mark(d) == 6/3*2 + + d = {"Niveau": 1, "Note": 3, "Bareme": 6} + assert df_marks_manip.note_to_mark(d) == 6/3*3 + + d = {"Niveau": 0, "Note": 3, "Bareme": 6} + assert df_marks_manip.note_to_mark(d) == 3 # ----------------------------- # Reglages pour 'vim'