Ejemplo n.º 1
0
def test_to_Dict():
    m = MultiSet([('a', 3), 7])
    assert m.multiplicity('a') == 3
    stockage = m.to_Dict()
    assert type(stockage) is dict
    assert stockage['a'] == 3
    assert stockage[7] == 1
    stockage['a'] = 9
    assert m.multiplicity('a') == 3
Ejemplo n.º 2
0
def test_supprime():
    param = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
    M = MultiSet(param)
    for element in M:
        M.ajoute(element,
                 2 + random.randrange(8))  # On ajoute de 2 à 9 éléments, donc
        # chaque élément est présent de 3 à 10 fois

    M.supprime(1, 20)
    assert 1 not in M
    assert M.multiplicity(1) == 0

    for element in param:
        avant = M.multiplicity(element)
        M.supprime(element, 3)
        apres = M.multiplicity(element)
        assert avant == 0 or apres < avant
Ejemplo n.º 3
0
def test_ajoute():
    m = MultiSet()
    # Signature
    for pas_un_nombre_valide in (-1, 0, 'a', [1, 2, 3]):
        m.ajoute('cobaye', pas_un_nombre_valide)
        assert 'cobaye' not in m

    # Axiomes
    m.ajoute(4)
    assert m.multiplicity(4) == 1
    m.ajoute('un mot', 145)
    assert m.multiplicity('un mot') >= 145

    m2 = MultiSet()

    for i in range(20):
        for n in (1, 4, 2, 7, 1, 3, 8, 9, 4):
            element = random.randrange(4)
            m1 = m2.copy()
            m2.ajoute(element, n)
            assert m2.multiplicity(element) - m1.multiplicity(element) == n
            assert len(m1) < len(m2)
            assert m1 < m2
Ejemplo n.º 4
0
def test_cut():
    M = MultiSet([
        0, 7, 4, 'lokkzeeazdq', {
            '2165': 132,
            '_': int,
            654: 46
        },
        MultiSet(), ('tout', 12), (1, 7, 5, set())
    ])
    N = MultiSet(
        "Ceci est un lorem ipsum sit dolor amet nec plus ultra hacked sans os. Avec windows 10. Donc il y a 1 os. Mé non. Paradoxe."
    )
    assert len(M.sup(6)) <= len(M)
    MSup = M.sup(7)
    for x in M.sup(7):
        assert M.multiplicity(x) > 7
    for x in M:
        assert not (M.multiplicity(x) > 7 and x not in MSup)

    NSup = N.sup(7)
    for x in N.sup(7):
        assert N.multiplicity(x) > 7
    for x in N:
        assert not (N.multiplicity(x) > 7 and x not in NSup)
Ejemplo n.º 5
0
def test_inf():
    M = MultiSet([
        0, 7, 4, 'lokkzeeazdq', {
            '2165': 132,
            '_': int,
            14: 46
        },
        MultiSet(), ('tout', 12), (1, 7, 5, set())
    ])
    N = MultiSet(
        "Ceci est un lorem ipsum sit dolor amet nec plus ultra hacked sans os. Avec windows 10. Donc il y a 1 os. Mé non. Paradoxe."
    )
    assert len(M.inf(3)) <= len(M)
    Minf = M.inf(9)
    for x in M.inf(9):
        assert M.multiplicity(x) < 9
    for x in M:
        assert not (M.multiplicity(x) < 9 and x not in Minf)

    Ninf = N.inf(9)
    for x in N.inf(9):
        assert N.multiplicity(x) < 9
    for x in N:
        assert not (N.multiplicity(x) < 9 and x not in Ninf)
Ejemplo n.º 6
0
def test_multiplicite():
    m = MultiSet()
    for i, lettre in enumerate(('a', 'b', 'c', 'd')):
        m.ajoute(lettre, i)
        assert m.multiplicity(lettre) == i

    m.ajoute('o', 18)
    assert m.multiplicity('o') == 18
    m.ajoute('o', 12)
    assert m.multiplicity('o') == 30

    assert m.multiplicity('test') == 0
    assert m.multiplicity({1: 2, 3: 4, 5: 6, 7: 8}) == 0

    m.ajoute('p', -5478)
    assert m.multiplicity('p') == 0

    m.supprime('o', 165465)
    assert m.multiplicity('o') == 0