DaftAcademy / daftacademy-python_4beginners-autumn2020

daftacademy-python_4beginners-autumn2020
9 stars 5 forks source link

Praca domowa 'Coraz bliżej święta' (mnożenie wielomianu) #6

Open ludaliaallen opened 3 years ago

ludaliaallen commented 3 years ago

Dzień dobry,

znowu mam problem z testami imul i imul2.

Moja funkcja __imul__ wygląda tak:

    def __imul__(self, other):
        if isinstance(other, int):
            mlist = []
            for c in self.coefs:
                mlist.append(c * other)
            self.coefs = tuple(mlist)
            return self
        elif isinstance(other, MyPolynomial):
            self.coefs = mul_tuple_to_tuple(self.coefs, other.coefs)
            return self
        else:
            return None

Gdzie coefs to współczynniki wielomianu w postaci tuple (a ta pomocnicza tak:)

def mul_tuple_to_tuple(t1, t2):
    m = len(t1)
    n = len(t2)
    prod = [0] * (m + n - 1)
    for i in range(m):
        for j in range(n):
            prod[i + j] += t1[i] * t2[j]
    res_t = tuple(prod)
    return res_t

Wszędzie tu zwracam self, modyfikuję jedynie pola bieżącego obiektu. Wyniki daje pożądane, nawet adresy obiektów w pamięci przed i po __imul__ są takie same, a jednak nie przechodzi to testów. Co robię nie tak? Na czym to ewentualnie testować?

wdebsqi commented 3 years ago

Wrzuć jakich testów nie przechodzi i jaki dostajesz error.

ludaliaallen commented 3 years ago

Napisałam: imul i imul_2 imul:

Traceback (most recent call last):
  File "/home/runner/unit_tests.py", line 129, in test_imul
    assert mp1 == mp2, "Something went wrong with: MyPolynomial *= MyPolynomial"
AssertionError: Something went wrong with: MyPolynomial *= MyPolynomial

imul_2:

Traceback (most recent call last):
  File "/home/runner/unit_tests.py", line 119, in test_imul_2
    assert mp1 == MyPolynomial(0), "Something went wrong with: MyPolynomial *= number"
AssertionError: Something went wrong with: MyPolynomial *= number
naboru commented 3 years ago

Zadania bazują na sobie. Jeśli nie masz poprzednich rozwiązanych to następne nie przejdą.

ludaliaallen commented 3 years ago

@naboru ale wszystkie poprzednie zadania mam rozwiązane i wszystkie testy przechodzą