Skip to content

Commit

Permalink
Presque fini pour #3, pour les derniers tests sur la gestion des inte…
Browse files Browse the repository at this point in the history
…rnats.

- un peu galère 😢
  • Loading branch information
Naereen committed Jul 26, 2018
1 parent 892a6a8 commit 9d5bb56
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ clean:
-rm -vfr __pycache__/ */__pycache__/ */*/__pycache__/ */*/*/__pycache__/ */*/*/*/__pycache__/
-rm -vf *.pyc */*.pyc */*/*.pyc */*/*/*.pyc */*/*/*/*.pyc */*/*/*/*.pyc

ignorelogs:
git checkout -- logs/

# Linters
# NPROC = `nproc`
# NPROC = 1
Expand Down
28 changes: 15 additions & 13 deletions tests/steps/ordreappel_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,38 @@ def VoeuClasse2candidat(voeu: VoeuClasse) -> str:
# On définit les étapes

@given("les candidat-e-s sont {liste_candidats}")
def step_impl(context, liste_candidats):
liste_candidats = liste_candidats.split(' ')
context.liste_candidats = liste_candidats
def step_impl(context, liste_candidats: str) -> None:
context.liste_candidats = [
candidat2VoeuClasse(candidat)
for candidat in liste_candidats.split(' ')
]

@given("le taux minimum de boursier-ère-s est {qb:d}")
def step_impl(context, qb):
def step_impl(context, qb: int) -> None:
context.qb = qb

@given("le taux minimum de résident-e-s est {qr:d}")
def step_impl(context, qr):
def step_impl(context, qr: int) -> None:
context.qr = qr

@when("l'appel est calculé")
def step_impl(context):
def step_impl(context) -> None:
if not hasattr(context, "qb"): context.qb = 0
if not hasattr(context, "qr"): context.qr = 0
groupe = GroupeClassement(0, context.qb, context.qr)
for candidat in context.liste_candidats:
groupe.ajouterVoeu(candidat2VoeuClasse(candidat))
groupe.ajouterVoeu(candidat)
groupes = [groupe]
entree = AlgoOrdreAppel(groupes)
entree.calculeOrdresAppels()
# un seul à extraire
ordreAppel = list(entree.ordresAppel.values())[0]
order_appel_calcule = [VoeuClasse2candidat(voeu) for voeu in ordreAppel]
context.order_appel_calcule = ' '.join(order_appel_calcule)
context.ordreAppel = ordreAppel

@then("l'ordre d'appel est {ordre_appel}")
def step_impl(context, ordre_appel):
assert len(context.order_appel_calcule) == len(ordre_appel)
# print("Ordre calculé =\n", context.order_appel_calcule)
def step_impl(context, ordre_appel: str) -> None:
order_appel_calcule = ' '.join([VoeuClasse2candidat(voeu) for voeu in context.ordreAppel])
assert len(order_appel_calcule) == len(ordre_appel)
# print("Ordre calculé =\n", order_appel_calcule)
# print("Ordre correct =\n", ordre_appel)
assert context.order_appel_calcule == ordre_appel
assert order_appel_calcule == ordre_appel
167 changes: 162 additions & 5 deletions tests/steps/propositions_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,182 @@
# On définit les étapes

@given("un internat disposant de {L:d} places")
def step_impl(context, L):
def step_impl(context, L: int) -> None:
context.L = L

@given("une liste de {M:d} candidat-e-s")
def step_impl(context, M):
def step_impl(context, M: int) -> None:
context.M = M

@given("un taux d'ouverture de {ouverture:d}")
def step_impl(context, ouverture):
def step_impl(context, ouverture: int) -> None:
context.ouverture = ouverture

@when("l'appel est lancé le jour {jour:d}")
def step_impl(context, jour):
def step_impl(context, jour: int) -> None:
context.jour = jour
groupeInternatUID = GroupeInternatUID(1, 1)
groupeInternat = GroupeInternat(groupeInternatUID, context.L, context.ouverture)
bmax = groupeInternat.calculeAssietteAdmission(context.M, context.L, context.jour, context.ouverture)
context.bmax = bmax

@then("{candidats:d} sont appelé-e-s")
def step_impl(context, candidats):
def step_impl(context, candidats: int) -> None:
assert context.bmax == candidats


# ---------------------
# On définit les étapes, second fichier

@given("une formation dont le rang limite de proposition est {rangLimite:d} et dont la capacité d'accueil est {capaciteFormation:d}")
def step_impl(context, rangLimite: int, capaciteFormation: int) -> None:
context.rangLimite = rangLimite
context.capaciteFormation = capaciteFormation

@given("un internat dont la capacité d'accueil est {capaciteInternat:d}")
def step_impl(context, capaciteInternat: int) -> None:
context.capaciteInternat = capaciteInternat

@given("la valeur de B est {B:d}")
def step_impl(context, B: int) -> None:
context.B = B

context.groupeAffectationUID = GroupeAffectationUID(1, 1, 1)
context.groupeAffectation = GroupeAffectation(context.capaciteFormation, context.groupeAffectationUID, context.rangLimite)

context.internatUID = GroupeInternatUID(1, context.groupeAffectation.id.G_TA_COD)
# XXX pourquoi le pourcentage d'ouverture est hardcodé à 10 ?
context.ouverture = 10
context.groupeInternat = GroupeInternat(context.internatUID, context.capaciteInternat, context.ouverture)

# FIXME valeurs de M, L, jour ?
context.M = 1
context.L = 1
context.jour = 1
B_calcule = context.groupeInternat.calculeAssietteAdmission(context.M, context.L, context.jour, context.ouverture)
assert B == B_calcule, "Erreur dans le calcul de B."

@given("les candidat-e-s à la formation sont {candidats}")
def step_impl(context, candidats: str) -> None:
context.candidatsFormation = [
candidat2VoeuClasse(candidat)
for candidat in candidats.split(' ')
]

@given("les candidat-e-s à l'internat sont {cdts_internat}")
def step_impl(context, cdts_internat: str) -> None:
context.candidatsInternat = [
candidat2VoeuClasse(candidat)
for candidat in cdts_internat.split(' ')
]

@given("les candidat-e-s à la formation sans internat sont {cdts_sans_internat}")
def step_impl(context, cdts_sans_internat: str) -> None:
context.candidatsSansInternat = [
candidat2VoeuClasse(candidat)
for candidat in cdts_sans_internat.split(' ')
]

@given("le classement à l'internat est {cl_internat}")
def step_impl(context, cl_internat: str) -> None:
context.internesClasses = [
candidat2VoeuClasse(candidat)
for candidat in cl_internat.split(' ')
]

@when("l'ordre d'appel est calculé")
def step_impl(context) -> None:
for candidat in context.candidatsInternat:
G_CN_COD = candidat.G_CN_COD
ordreAppel = context.candidatsFormation.index(candidat) + 1
rangInternat = context.internesClasses.index(candidat) + 1
VoeuEnAttente.ajouterVoeu(
G_CN_COD,
context.groupeAffectation,
ordreAppel,
avecInternat=True,
internat=context.groupeInternat,
rangInternat=rangInternat,
)

for candidat in context.candidatsSansInternat:
G_CN_COD = candidat.G_CN_COD
ordreAppel = context.candidatsFormation.index(candidat) + 1
VoeuEnAttente.ajouterVoeu(
G_CN_COD,
context.groupeAffectation,
ordreAppel,
)

entree = AlgoPropositions(
[context.groupeAffectation],
[context.groupeInternat]
)
GroupeInternat.nbJoursCampagne = 1
# calcule la sortie
entree.calculePropositions()
context.sortie = entree


@then("les candidat-e-s suivant-e-s reçoivent une proposition pour la formation {prop_formation}")
def step_impl(context, prop_formation: str) -> None:
context.prop_formation = context.sortie.propositions
assert context.prop_formation = [
candidat2VoeuClasse(candidat)
for candidat in prop_formation.split(' ')
]

# idCandidatsRetenus = sortie.propositions.stream()
# .sorted(Comparator.comparing(voeuEnAttente -> voeuEnAttente.ordreAppel))
# .map(voeuEnAttente -> voeuEnAttente.id.G_CN_COD)
# .distinct()
# .collect(Collectors.toList())

# candidatsRetenusFormationAttendus = Arrays.stream(candidatsRetenusFormation.split(" "))
# .filter(candidat -> !candidat.equals(("-")))
# .map(candidat -> Integer.parseInt(candidat.substring(1)))
# .collect(Collectors.toList())
# Assertions.assertThat(idCandidatsRetenus).containsExactlyElementsOf(candidatsRetenusFormationAttendus)

@then("les candidat-e-s suivant-e-s reçoivent une proposition pour l'internat {prop_internat}")
def step_impl(context, prop_internat: str) -> None:
context.prop_internat = context.sortie.internats_sortie
assert context.prop_internat == [
candidat2VoeuClasse(candidat)
for candidat in prop_internat.split(' ')
]

# idCandidatsRetenusInternat = sortie.propositions.stream()
# .sorted(Comparator.comparing(voeuEnAttente -> voeuEnAttente.rangInternat))
# .filter(voeuEnAttente -> voeuEnAttente.id.I_RH_COD)
# .map(voeuEnAttente -> voeuEnAttente.id.G_CN_COD)
# .distinct()
# .collect(Collectors.toList())

# candidatsRetenusAttendus = Arrays.stream(candidatsRetenusInternat.split(" "))
# .filter(candidat -> !candidat.equals(("-")))
# .map(candidat -> Integer.parseInt(candidat.substring(1)))
# .collect(Collectors.toList())
# Assertions.assertThat(idCandidatsRetenusInternat).containsExactlyElementsOf(candidatsRetenusAttendus)

@then("les candidat-e-s suivant-e-s sont en attente pour l'internat {en_attente}")
def step_impl(context, en_attente: str) -> None:
context.en_attente = context.sortie.enAttentes
assert context.en_attente == [
candidat2VoeuClasse(candidat)
for candidat in en_attente.split(' ')
]

# idCandidatsEnAttente = sortie.enAttente.stream()
# .sorted(Comparator.comparing(voeuEnAttente -> voeuEnAttente.rangInternat))
# .filter(voeuEnAttente -> voeuEnAttente.id.I_RH_COD)
# .map(voeuEnAttente -> voeuEnAttente.id.G_CN_COD)
# .distinct()
# .collect(Collectors.toList())

# candidatsEnAttenteAttendusTab = Arrays.stream(candidatsEnAttenteAttendus.split(" "))
# .filter(candidat -> !candidat.equals(("-")))
# .map(candidat -> Integer.parseInt(candidat.substring(1)))
# .collect(Collectors.toList())

# Assertions.assertThat(idCandidatsEnAttente).containsExactlyElementsOf(candidatsEnAttenteAttendusTab)

0 comments on commit 9d5bb56

Please sign in to comment.