I'm trying to apply pytest on a project that uses the Bhaskara Formula, because it's giving it error and I'm not able to solve it. Then the codes will go with the error. Thank you.
import math
class Bhaskara:
def delta(self, a, b, c):
return b ** 2 - 4 * a * c
def calcula_raizes(self, a, b, c):
d = self.delta(a, b, c)
if d == 0:
raiz1 = (-b + math.sqrt(d)) / (2 * a)
return 1, raiz1
else:
if d < 0:
return 0
else:
raiz1 = (-b + math.sqrt(d)) / (2 * a)
raiz2 = (-b - math.sqrt(d)) / (2 * a)
return 2, raiz1, raiz2
import Bhaskara
import pytest
class Test_Bhaskara:
@pytest.fixture
def b(self):
return Bhaskara.Bhaskara()
@pytest.mark.parametrize("entrada, saida", [
((1, 0, 0), (1, 0,)),
((1, -5, 6), (2, 3, 2)),
((10, 10, 10), (0,)),
((10, 20, 10), (1, -1))
])
def testa_bhaskara(self, entrada, saida):
b = Bhaskara()
assert b.calcula_raizes(entrada) == saida
Pytest output
___ Test_Bhaskara.testa_bhaskara[entrada3-saida3] ___
self = <Test_Bhaskara.Test_Bhaskara instance at 0x7f1ea0453680>
entrada = (10, 20, 10), saida = (1, -1)
@pytest.mark.parametrize("entrada, saida", [
[(1, 0, 0,), (1, 0,)],
[(1, -5, 6,), (2, 3, 2,)],
[(10, 10, 10,), (0,)],
[(10, 20, 10,), (1, -1,)]
])
def testa_bhaskara(self, entrada, saida):
b = Bhaskara()
TypeError: 'module' object is not callable
Test_Bhaskara.py:14: TypeError
========= 4 failed in 0.04 seconds =========