예제 #1
0
파일: calculator.py 프로젝트: marklap/Py300
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"
예제 #2
0
 def test_divide(self):
     self.assertTrue(isclose(calc.divide(self.x, self.y), 0.6666666666))
예제 #3
0
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"
예제 #4
0
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_divide_function_returns_correct_result(self):
     self.assertEqual(calculator_functions.divide(10, 5), 2)
     #self.assertRaises(ValueError,calculator_functions.divide,10,0)
     with self.assertRaises(ValueError):  #-->
         calculator_functions.divide(10, 0)
 def test_divide(self):
     self.assertAlmostEqual(calc.divide(self.x, self.y), .6666, places=3)
 def test_divide(self):
     self.assertAlmostEqual(calc.divide(self.x, self.y), .6666, places=3 )
예제 #8
0
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")
예제 #9
0
 def test_divide(self):
     self.assertEqual(calc.divide(self.y, self.x), 1.5)
 def test_divide(self):
     self.assertTrue(isclose(calc.divide(self.x, self.y), 0.6666666666))
예제 #11
0
 def test_divide_by_zero_returns_value_error(self):
     with self.assertRaises(ZeroDivisionError):
         calculator_functions.divide(3, 0)
예제 #12
0
 def test_division(self):
     self.assertEqual(calculator_functions.divide(6, 2), 3)