def main(): if len(sys.argv) != 4: error_message = """ Invalid arguments. Usage: calculator.py 1 + 3 or 1 x 3 or 1 / 3 or 1 - 3 """ raise ValueError(error_message + "\n") x = sys.argv[1] operator = sys.argv[2] y = sys.argv[3] if operator == "+": return functions.add(x, y) elif operator == "-": return functions.subtract(x, y) elif operator == "x": return functions.multiply(x, y) elif operator == "/": return functions.divide(x, y) else: return "invalid input"
def test_add(self): self.assertEqual(calc.add(self.x, self.y), 5)
def test_add(): assert calc.add(2, 3) == 5
def test_add2(self): print("running test_add2") self.assertEqual(calc.add(7, 8), 15)
def test_add(self): print("running test_add") self.assertEqual(calc.add(self.x, self.y), 5)
if len(sys.argv) != 4: error_message = """ Invalid arguments. Usage: calculator.py 1 + 3 """ sys.stderr.write(error_message + "\n") sys.exit(-1) x = sys.argv[1] operator = sys.argv[2] y = sys.argv[3] if operator == "+": print functions.add(x, y) elif operator == "-": print functions.subtract(x, y) elif operator == "*": print functions.multiply(x, y) elif operator == "/": print functions.divide(x, y) else: print "invalid input"
def test_calculator_add_function_returns_correct_result(self): self.assertEqual(4, calculator_functions.add(2, 2)) self.assertEqual(1, calculator_functions.add(-1, 2)) self.assertEqual(-3, calculator_functions.add(0, -3))
if len(sys.argv) != 4: error_message = """ Invalid arguments. Usage: calculator.py 1 + 3 """ sys.stderr.write(error_message + "\n") sys.exit(-1) x = sys.argv[1] operator = sys.argv[2] y = sys.argv[3] if operator == "+": print(functions.add(x, y)) elif operator == "-": print(functions.subtract(x, y)) elif operator == "*": print(functions.multiply(x, y)) elif operator == "/": print(functions.divide(x, y)) else: print("invalid input")