Exemplo n.º 1
0
def test_unitaire_6(visible=False):
    print("*** rationnel: test_unitaire_6 ***")

    a = rationnel.rationnel(entier.entier(-15), entier.entier(-40))

    ok = (a.est_valide() and \
     (a.lire_num().lire_valeur() == 3) and (a.lire_denom().lire_valeur() == 8))

    return ok
Exemplo n.º 2
0
def test_unitaire_15(visible=False):
    print("*** entier: test_unitaire_15 ***")

    a = entier.entier(-55)
    b = entier.entier()
    x = a / b

    ok = (x.est_valide() == False)

    return ok
Exemplo n.º 3
0
def test_unitaire_13(visible=False):
    print("*** entier: test_unitaire_13 ***")

    a = entier.entier(-54)
    b = entier.entier(6)
    x = a / b

    ok = (x.est_valide() and x.lire_valeur() == -9)

    return ok
Exemplo n.º 4
0
def test_unitaire_12(visible=False):
    print("*** entier: test_unitaire_12 ***")

    a = entier.entier(-1)
    n = entier.entier(-10)
    x = a**n

    ok = (x.est_valide() and x.lire_valeur() == 1)

    return ok
Exemplo n.º 5
0
def test_unitaire_10(visible=False):
    print("*** entier: test_unitaire_10 ***")

    a = entier.entier(0)
    n = entier.entier(6)
    x = a**n

    ok = (x.est_valide() and x.lire_valeur() == 0)

    return ok
Exemplo n.º 6
0
def test_unitaire_8(visible=False):
    print("*** entier: test_unitaire_8 ***")

    a = entier.entier(5)
    n = entier.entier(6)
    x = a**n

    ok = (x.est_valide() and x.lire_valeur() == 15625)

    return ok
Exemplo n.º 7
0
def test_unitaire_5(visible=False):
    print("*** entier: test_unitaire_5 ***")

    a = entier.entier(5)
    b = entier.entier(6)
    x = a - b

    ok = (x.est_valide() and x.lire_valeur() == -1)

    return ok
Exemplo n.º 8
0
def test_unitaire_4(visible=False):
    print("*** entier: test_unitaire_4 ***")

    a = entier.entier(5)
    b = entier.entier(6, False)
    x = a + b

    ok = (x.est_valide() == False and x.lire_valeur() == 0)

    return ok
Exemplo n.º 9
0
def test_unitaire_11(visible=False):
    print("*** entier: test_unitaire_11 ***")

    a = entier.entier(0)
    n = entier.entier(0)
    x = a**n

    ok = (not x.est_valide())

    return ok
Exemplo n.º 10
0
def test_unitaire_2(visible=False):
    print("*** entier: test_unitaire_2 ***")

    a = entier.entier(5, 0 == 1)

    ok = (not a.est_valide())

    return ok
Exemplo n.º 11
0
def test_unitaire_7(visible=False):
    print("*** entier: test_unitaire_7 ***")

    a = entier.entier(5, False)
    x = -a

    ok = (x.est_valide() == False and x.lire_valeur() == 0)

    return ok
Exemplo n.º 12
0
def test_unitaire_18(visible=False):
    print("*** rationnel: test_unitaire_18 ***")

    a = rationnel.rationnel(entier.entier(5), -4)
    b = rationnel.rationnel(0, 3)
    x = a / b

    ok = (not x.est_valide())

    return ok
Exemplo n.º 13
0
def test_unitaire_19(visible=False):
    print("*** rationnel: test_unitaire_19 ***")

    a = rationnel.rationnel(entier.entier(5), -4)
    b = rationnel.rationnel(2, 3, False)
    x = a + b

    ok = (not x.est_valide())

    return ok
Exemplo n.º 14
0
def test_unitaire_0(visible=False):
    print("*** entier: test_unitaire_0 ***")

    a = entier.entier(5)
    if visible:
        print(a)
        print(repr(a))

    ok = True

    return ok
Exemplo n.º 15
0
def test_unitaire_6(visible=False):
    print("*** entier: test_unitaire_6 ***")

    a = entier.entier(5)
    x = -a
    y = a.oppose()

    ok = ((x.est_valide() and x.lire_valeur() == -5) and \
     (y.est_valide() and y.lire_valeur() == -5))

    return ok
Exemplo n.º 16
0
def test_unitaire_9(visible=False):
    print("*** rationnel: test_unitaire_9 ***")

    a = rationnel.rationnel(entier.entier(5), -4)
    b = rationnel.rationnel(2, 3)
    x = a / b

    ok = (x.est_valide() and \
     x.lire_num().lire_valeur() == -15 and x.lire_denom().lire_valeur() == 8)

    return ok
Exemplo n.º 17
0
    def __init__(self, num=0, denom=1, valide=True):
        """ constructeur """
        if (not valide) or (denom == 0):
            num, denom = 0, 1
            valide = False

        num_ok = False

        if isinstance(num, int):
            self.__num = entier.entier(num)
            num_ok = True

        if isinstance(num, entier.entier):
            self.__num = num
            num_ok = num.est_valide()

        denom_ok = False

        if isinstance(denom, int):
            self.__denom = entier.entier(denom)
            denom_ok = True

        if isinstance(denom, entier.entier):
            self.__denom = denom
            denom_ok = denom.est_valide()

        self.__valide = valide and \
         (num_ok and denom_ok) and \
         (not self.__denom.est_zero())

        if self.__valide:
            p = self.__num.lire_valeur()
            q = self.__denom.lire_valeur()

            if q < 0:
                p, q = -p, -q

            n = entier.pgcd_entiers(p, q)

            self.__num = entier.entier(p // n)
            self.__denom = entier.entier(q // n)
        else:
            self.__num = entier.entier(0, False)
            self.__denom = entier.entier(1)