def test_subtract(self): logger = logging.getLogger() test_case = [[3, 2], [0, 1], [-15, 10], [321, .1], ['a', 'b']] expected_result = [1, -1, -25, 320.9, None] for i in range(len(expected_result)): if expected_result[i] == calculator.subtract(test_case[i]): print('{} Subtract-{}\nTest Case: {}\nExpected: {}\nOutput: {}'.format( datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), i, test_case[i], expected_result[i], calculator.subtract(test_case[i]))) print('Pass\n') logger.info('Subtract-{}, {}, {}, {}, Pass, '.format( i, ' '.join((str(x) for x in test_case[i])), calculator.subtract(test_case[i]), expected_result[i])) else: print('{} Subtract-{}\nTest Case: {}\nExpected: {}\nOutput: {}'.format( datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), i, test_case[i], expected_result[i], calculator.subtract(test_case[i]))) logger.info('Subtract-{}, {}, {}, {}, Fail, '.format( i, ' '.join((str(x) for x in test_case[i])), calculator.subtract(test_case[i]), expected_result[i])) print('Fail\n') print('------------------------------------------')
def test_subtract(): test3 = subtract(10, 5) assert(test3 == 5) test4 = subtract(4, 6) assert(test4 == -2) test5 = subtract(2.5, 6.8) assert(test5 == -4.3)
def test_subtract(self): """Test the subtract function. Input of the test are two numbers. Output of the test is a subtraction of two numbers. """ self.assertEqual(calculator.subtract(20, 10), 10) self.assertEqual(calculator.subtract(-40, 10), -50) self.assertEqual(calculator.subtract(-5, -5), 0)
def test_subtraction(): """ Unit test to test subtraction function from the "Calculator" program The unit test tests output for both positive and negative int and float inputs Parameters ---------- None Returns ------- None """ assert calculator.subtract(7, 3) == 4 assert calculator.subtract(7.0, 3.0) == 4.0 assert calculator.subtract(7, -3) == 10 assert calculator.subtract(7.0, -3.0) == 10.0
def simpleCalculator(a,b,op): # op = operation if op == '+': result = calculator.add(a,b) elif op == '-': result = calculator.subtract(a,b) elif op == '*': result = calculator.multiply(a,b) elif op == '/': result = calculator.divide(a,b) result = int(result) return result
def test_subtraction_null_values(self): with pytest.raises(TypeError, match="unsupported operand type"): calculator.subtract(2, None) with pytest.raises(TypeError, match="unsupported operand type"): calculator.subtract(None, 2) with pytest.raises(TypeError, match="unsupported operand type"): calculator.subtract(None, None)
def test_subtraction(self): assert 2 == calculator.subtract(4, 2) assert 0 == calculator.subtract(4, 4) assert 0 == calculator.subtract(-4, -4) assert 8 == calculator.subtract(4, -4) assert -8 == calculator.subtract(-4, 4) assert 2.5 == calculator.subtract(4, 1.5)
def result(): var_1 = request.form.get("var_1", type=int) var_2 = request.form.get("var_2", type=int) operation = request.form.get("operation") if (operation == 'Addition'): result = add(var_1, var_2) elif (operation == 'Subtraction'): result = subtract(var_1, var_2) elif (operation == 'Multiplication'): result = multiply(var_1, var_2) elif (operation == 'Division'): result = division(var_1, var_2) else: result = 'INVALID CHOICE' entry = result return render_template('result.html', entry=entry)
def test_Subtraction(self): #Subtracting two positives self.assertEqual(calculator.subtract(5, 2), 3) #Subtracting to 0 self.assertEqual(calculator.subtract(5, 5), 0) #Subtracting into negatives self.assertEqual(calculator.subtract(5, 6), -1) #Subtracting negative self.assertEqual(calculator.subtract(5, -2), 7) #Subtracting from negative self.assertEqual(calculator.subtract(-5, 2), -7) #Subtracting two negatives self.assertEqual(calculator.subtract(-5, -2), -3) #Subtracting decimals self.assertEqual(calculator.subtract(5.5, 2), 3.5)
def evaluate(choice): """Evaluate the choice and make the calculation. Input of the function are choice, n1, n2. Output of the function is a calculation of two numbers. """ # Use the add function and print the result. if choice == 1: print(n1, "+", n2, "=", calculator.add(n1, n2)) # Use the subtract function and print the result. elif choice == 2: print(n1, "-", n2, "=", calculator.subtract(n1, n2)) # Use the multiply function and print the result. elif choice == 3: print(n1, "*", n2, "=", calculator.multiply(n1, n2)) # Use the divide function and print the result. elif choice == 4: print(n1, "/", n2, "=", calculator.divide(n1, n2))
def test_subtraction(self): """substraction.""" assert 2 == calculator.subtract(4, 2)
def test_subtract(self): assert 2 == calculator.subtract(5, 3)
def test_subtraction(self): assert 2 == calculator.subtract(4, 2)
def test_subtract(self): self.assertEqual(calculator.subtract(4, 3), 1)
def test_subtract_not_equal(self): self.assertNotEqual(calculator.subtract(4, 4), 2)
def test1(self): self.assertEqual(calculator.subtract(4, 2), 2)
def test_subtract(self): self.assertEqual(calculator.subtract(1, 2), -1) self.assertEqual(calculator.subtract(10, 2), 8) self.assertEqual(calculator.subtract(-10, 2), -12) self.assertEqual(calculator.subtract(-10, -6), -4)
def test_subtract(self): self.assertEqual(8, calculator.subtract(10, 2))
def test_subtract(): value = calculator.subtract(3.0, 2.0) assert value == 1.0
def test_subtract(a, b, expected): from calculator import subtract result = subtract(a, b) assert result == pytest.approx(expected)
def testSubtract(): assert (calculator.subtract(0,3) == -3) assert (calculator.subtract(5,0) == 5) assert (calculator.subtract(-1,-7) == 6) assert (calculator.subtract(-8,3) == -11)
print('Great! Now enter the second number: ') second = int(input()) choice = 0 #let's output a menu while choice != 5: print('Choose what you\'d like to do with ' + str(first) + ' and ' + str(second) + ':') print('\t1: add') print('\t2: subtract') print('\t3: multiply') print('\t4: divide') print('\t5: exit') choice = int(input()) # this series of if-statements call the proper functions from within the calculator program if choice == 1: print('The calculator returned: ' + str(calculator.add( first, second ))) elif choice == 2: print('The calculator returned: ' + str(calculator.subtract( first, second ))) elif choice == 3: print('The calculator returned: ' + str(calculator.multiply( first, second ))) elif choice == 4: print('The calculator returned: ' + str(calculator.divide( first, second ))) elif choice == 5: print('Goodbye!') else: print('Sorry that\'s not a valid choice. Try again.')
def test_subtract_negative(): value = calculator.subtract(3.0, 2.0) assert value == -1.0
def test_subtract(self): self.assertEqual(subtract(10,4), 6)
def testSubtractTest(self): self.assertEqual(calculator.subtract (7,5), 2) self.assertEqual(calculator.subtract (4,2), 2) self.assertEqual(calculator.subtract (8,3), 11)
import calculator a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(a,"+",b,"=",calculator.add(a, b)) print(a,"-",b,"=",calculator.subtract(a, b)) print(a,"*",b,"=",calculator.multiply(a, b)) print(a,"/",b,"=",calculator.divide(a, b))
from calculator import creator, add, subtract from math import sqrt print(creator) print(add(2, 3)) print(subtract(10, 5)) print(sqrt(49))
def test_subtract(self): result = subtract(5,3) self.assertEqual(result,2)
def test2(self): self.assertEqual(calculator.subtract(8, 2), 6)
def test_Subtract(self): self.assertEqual(calculator.subtract(15,10),5)
def test_subtract(self): self.assertEqual(calc.subtract(10, 5), 5) self.assertEqual(calc.subtract(-1, 1), -2) self.assertEqual(calc.subtract(-1, -1), 0)
def test_operator(self): self.assertEqual(calculator.add(13,11),24) self.assertEqual(calculator.subtract(15,-10),25) self.assertEqual(calculator.divide(16,2),8) self.assertEqual(calculator.multiply(7,-3),-21)
def test_subtract_positive_to_negative(self): self.assertEqual(calculator.subtract(4, -4), 8)
def test_subtract(self): result = calculator.subtract(9, 8) self.assertEqual(1, result)
def test_subtract_positive_to_zero(self): self.assertEqual(calculator.subtract(42, 0), 42)
import calculator as calc x = 20 y = 5 z = calc.add(x, y) print("Add:", z) z = calc.subtract(x, y) print("Sub:", z) z = calc.multiply(x, y) print("Mul:", z) z = calc.divide(x, y) print("Div:", z)
def post(self): return subtract(request.get_json())