예제 #1
0
def test_couts():
    """Vérifie qu'un cout doit être positif."""
    with pytest.raises(ValueError):
        Couts(-30, 100, 40)
        with pytest.raises(ValueError):
            Couts(30, -100, 40)
            with pytest.raises(ValueError):
                Couts(30, 100, -40)
예제 #2
0
def test_encode_couts():
    """Teste l'encodage d'une ligne en objet de classe Couts."""
    correspondance = {
        "100 / 200 / 40":
        Couts(changement=100, sur_effectif=200, sous_effectif=40),
        "10 / 2000 / 400":
        Couts(changement=10, sur_effectif=2000, sous_effectif=400)
    }
    for entree, attendu in correspondance.items():
        assert attendu == Probleme._encode_couts(entree)
예제 #3
0
def probleme_sans_solution():
    """Retranscription du problème d'exemple en graphe."""
    return Probleme(personnel=[
        Prerequis(mois="Février", nb_employes_min=3, nb_employes_max=Inf),
        Prerequis(mois="Mars", nb_employes_min=7, nb_employes_max=7)
    ],
                    echange=Echange(3, 1 / 3),
                    couts=Couts(160, 200, 200),
                    h_supp=1 / 4)
예제 #4
0
def probleme():
    """Problème utilisé pour les tests."""
    return Probleme(personnel=[
        Prerequis(mois="Février", nb_employes_min=3, nb_employes_max=Inf),
        Prerequis(mois="Mars", nb_employes_min=4, nb_employes_max=Inf),
        Prerequis(mois="Avril", nb_employes_min=2, nb_employes_max=2)
    ],
                    echange=Echange(1, 1 / 2),
                    couts=Couts(90, 100, 300),
                    h_supp=1 / 4)
def probleme_non_valide():
    """Problème ne pouvant pas être résolu."""
    return Probleme(
        personnel = [
            Prerequis(mois = "Février", nb_employes_min = 3, nb_employes_max = Inf),
            Prerequis(mois = "Mars", nb_employes_min = 1, nb_employes_max = 1)
        ],
        echange = Echange(3, 1/3),
        couts = Couts(160, 200, 200),
        h_supp = 1/4
    )
예제 #6
0
def test_repr():
    """Teste le repr."""
    probleme = Probleme(personnel=[
        Prerequis(mois="Mars", nb_employes_min=2, nb_employes_max=Inf),
        Prerequis(mois="Avril", nb_employes_min=4, nb_employes_max=4)
    ],
                        echange=Echange(3, .33),
                        couts=Couts(160, 200, 200),
                        h_supp=1 / 4)
    assert (
        repr(probleme) ==
        "Probleme(personnel = [Prerequis(mois='Mars', nb_employes_min=2, nb_employes_max=inf), Prerequis(mois='Avril', nb_employes_min=4, nb_employes_max=4)], echange = Echange(ajout_max=3, suppression_max=0.33), couts = Couts(changement=160, sur_effectif=200, sous_effectif=200), h_supp = 0.25)"
    )
def test_inputs_graphe(probleme):
    """Teste la fonction qui renvoie les arguments du graphe."""
    grapheD = GrapheD(probleme)
    sortie = grapheD._inputs_graphe
    attendu = (
        "Février - 3",
        "Avril - 2",
        ["Février", "Mars", "Avril"],
        [3, 4, 2],
        [Inf, Inf, 2],
        Echange(ajout_max=1, suppression_max=0.5),
        Couts(changement=90, sur_effectif=100, sous_effectif=300),
        0.25
    ) 
    assert "_inputs_graphe" not in vars(grapheD)
    assert sortie == attendu
예제 #8
0
def couts():
    """Coûts utilisés dans les tests."""
    return Couts(160, 200, 200)