Exemplo n.º 1
0
def init():
   if request.method == 'POST':
       item1 = int(request.form['item1input'])
       item2 = int(request.form['item2input'])
       oper = switcher.get(request.form['Operator'])
   else:
       item1 = int(request.args.get('item1input'))
       item2 = int(request.args.get('item2input'))
       oper = switcher.get(request.args.get('Operator'))
       print("item1" + str(item1) + " item2 " + str(item2) + " Operator :" + oper)
   tempCalculatorObject = CalculatorClass (item1, item2, oper)
   return render_template('result.html', item1 = str(tempCalculatorObject.item1), item2 = str(tempCalculatorObject.item2),
                          oper = str(tempCalculatorObject.operator), result = str(tempCalculatorObject.runOperation()))
Exemplo n.º 2
0
 def test_init(self):
     tempCalculatorObject = CalculatorClass(1, 5, 2)
     self.assertEqual(tempCalculatorObject.item1, 1)
     self.assertEqual(tempCalculatorObject.item2, 5)
     self.assertEqual(tempCalculatorObject.operator, 2)
Exemplo n.º 3
0
 def test_runOperationExponent(self):
     tempCalculatorObject = CalculatorClass(12, 1, "**")
     self.assertEqual(tempCalculatorObject.runOperation(), 12)
Exemplo n.º 4
0
 def test_runOperationModulo(self):
     tempCalculatorObject = CalculatorClass(12, 500, "%")
     self.assertEqual(tempCalculatorObject.runOperation(), 12)
Exemplo n.º 5
0
 def test_runOperationNegativeSubtraction(self):
     tempCalculatorObject = CalculatorClass(12, 500, "-")
     self.assertEqual(tempCalculatorObject.runOperation(), -488)
Exemplo n.º 6
0
 def test_runOperationMultiplication(self):
     tempCalculatorObject = CalculatorClass(12, 500, "*")
     self.assertEqual(tempCalculatorObject.runOperation(), 6000)
Exemplo n.º 7
0
 def test_runOperationZeroDivision(self):
     tempCalculatorObject = CalculatorClass(1, 0, "/")
     with self.assertRaises(ZeroDivisionError):
         tempCalculatorObject.runOperation()
Exemplo n.º 8
0
 def test_runOperationInvalidOuput(self):
     tempCalculatorObject = CalculatorClass(1, 5, 2)
     self.assertEqual(tempCalculatorObject.runOperation(), "invalid output")
Exemplo n.º 9
0
 def test_setOperator(self):
     tempCalculatorObject = CalculatorClass(1, 5, 2)
     tempCalculatorObject.setOperator("+")
     self.assertEqual(tempCalculatorObject.operator, "+")