tests for df_marks_manip

This commit is contained in:
Benjamin Bertrand 2016-11-13 16:14:32 +03:00
parent 5e8c955867
commit 780a7c53af
2 changed files with 55 additions and 5 deletions

View File

@ -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
#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"],

View File

@ -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'