class Test_MiCalculadora(unittest.TestCase): def setUp(self): self.calc = Calculadora() def test_inicial_valores(self): self.assertEqual(0, self.calc.valor) def test_metodo_suma(self): self.calc.add(1, 3) self.assertEqual(4, self.calc.valor) def test_metodo_resta(self): self.calc.substract(10, 5) self.assertEqual(5, self.calc.valor) def test_metodo_multiplicacion(self): self.calc.multiply(6, 3) self.assertEqual(18, self.calc.valor) def test_metodo_division(self): self.calc.divide(15, 3) self.assertEqual(5, self.calc.valor) def test_metodo_divisioncero(self): self.calc.divide(15, 0) self.assertEqual(NULL, self.calc.valor)
class Test_MiCalculadora(unittest.TestCase): def setUp(self): self.calc = Calculadora() def test_inicial_valores(self): self.assertEqual(0, self.calc.valor) def test_metodo_suma(self): self.calc.add(1, 3) self.assertEqual(4, self.calc.valor)
def calcula_resultado(self): if self.equacao.get() == Constantes.COD(): webbrowser.open_new(url=Constantes.URL()) self.clr_label = True return self.var = str(Calculadora.calcula(expressao=self.equacao.get())) self.equacao.set(self.var) self.clr_label = True
class Test_MiCalculadora(unittest.TestCase): def setUp(self): self.calc = Calculadora() def test_inicial_valores(self): self.assertEqual(0, self.calc.valor) def test_metodo_suma(self): self.calc.add(1, 3) self.assertEqual(4, self.calc.valor) def test_metodo_resta(self): self.calc.substract(7, 5) self.assertEqual(2, self.calc.valor) def test_metodo_division(self): self.calc.divide(13, 2) self.assertEqual(6.5, self.calc.valor) def test_metodo_multiplicacion(self): self.calc.multiplication(9, 4) self.assertEqual(36, self.calc.valor)
def setUp(self): self.calc = Calculadora()
def test_soma(): assert Calculadora.calcula(expressao='5+5+15') == 25
def test_expressao_invalida(): with pytest.raises(Exception): assert Calculadora.calcula(expressao='5 + a')
def test_multiplas_operacoes(): assert Calculadora.calcula(expressao='(5 * 3 + 5 /5 - 8 ) + 5**2') == 33
def test_divisao_por_zero(): with pytest.raises(ZeroDivisionError): assert Calculadora.calcula(expressao='5/0')
def test_divisao(): assert Calculadora.calcula(expressao='10/5') == 2
def test_multiplicacao(): assert Calculadora.calcula(expressao='10 * 15') == 150
def test_subtracao(): assert Calculadora.calcula(expressao='10-15 -5- 7') == -17
class Test_MiCalculadora(unittest.TestCase): def setUp(self): self.calc = Calculadora() def tearDown(self): del self.calc def test_inicial_valores(self): self.assertEqual(0, self.calc.valor) def test_metodo_suma(self): self.calc.add(1, 3) self.assertEqual(4, self.calc.valor) def test_divide(self): self.assertEqual(self.calc.divide(-1, 1), -1) self.assertEqual(self.calc.divide(-1, -1), 1) self.assertEqual(self.calc.divide(5, 2), 2.5) self.assertEqual(self.calc.divide(8, 2), 4) with self.assertRaises(ZeroDivisionError): self.calc.divide(10, 0) self.calc.divide(10, 0) def test_divide_int(self): self.assertEqual(self.calc.divide_int(11, 2), 5) self.assertEqual(self.calc.divide_int(-1, 1), -1) self.assertEqual(self.calc.divide_int(-1, -1), 1) self.assertEqual(self.calc.divide_int(8, 2), 4) with self.assertRaises(ZeroDivisionError): self.calc.divide(10, 0) self.calc.divide(0, 0)
from flask import Flask, jsonify, request from calculadora.calculadora import Calculadora app = Flask(__name__) calculadora = Calculadora() # GET @app.route('/somar') def calcula_soma(): '''Rota para obter o nomes dos dispositivos''' try: body = request.get_json() response = calculadora.somar( body.get("elemento1"), body.get("elemento2")) except Exception as err: return jsonify({"message": err}) return jsonify(response), 200 @app.route('/subtrair') def calcula_subtracao(): '''Rota para obter o nomes dos dispositivos''' try: body = request.get_json() response = calculadora.subtrair( body.get("elemento1"), body.get("elemento2")) except Exception as err: return jsonify({"message": err}) return jsonify(response), 200