Exemplo n.º 1
0
 def test_subtraction(self):
     # Floats
     result = calculator.subtraction(5, 2.5)
     self.assertEqual(result, 2.5)
     # Zero
     result = calculator.subtraction(0, 4.75)
     self.assertEqual(result, -4.75)
     # Negative
     result = calculator.subtraction(-4, -5)
     self.assertEqual(result, 1)
     # Non-numeric
     result = calculator.subtraction(3, "subtract")
     self.assertEqual(result, None)
Exemplo n.º 2
0
def test_subtraction_negative_a():
    """
    Test that subtraction a - b works with a being negative.

    Example: a = -2, b = 1 -> "-2 - 1 = -3"
    """
    assert calculator.subtraction(-2, 1) == "-2 - 1 = -3"
Exemplo n.º 3
0
def test_subtraction_negative_numbers():
    """
    Test that subtraction a - b works with both being negative.

    Example: a = -2, b = -1 -> "-2 - (-1) = -1"
    """
    assert calculator.subtraction(-2, -1) == "-2 - -1 = -1"
Exemplo n.º 4
0
def test_subtraction_negative_b():
    """
    Test that subtraction a - b works with b being negative.

    Example: a = 3, b = -1 -> "3 - (-1) = 4"
    """
    assert calculator.subtraction(3, -1) == "3 - -1 = 4"
Exemplo n.º 5
0
def test_subtraction_positive_numbers():
    """
    Test that subtraction a - b works with both being positive.

    Example: a = 3, b = 1 -> "3 - 1 = 2"
    """
    assert calculator.subtraction(3, 1) == "3 - 1 = 2"
Exemplo n.º 6
0
    def test_three_operands_values(self):
        from calculator import subtraction

        operands = "/9/12/-1"
        expected_values = "Operands provided: [9, 12, -1]"
        actual = subtraction(operands)
        self.assertTrue(expected_values in actual)
Exemplo n.º 7
0
    def test_one_operand_result(self):
        from calculator import subtraction

        operands = "5"
        expected_result = "5"
        actual = subtraction(operands)
        self.assertTrue(expected_result in actual)
Exemplo n.º 8
0
    def test_one_operand_values(self):
        from calculator import subtraction

        operands = "5"
        expected_values = "Operands provided: [5]"
        actual = subtraction(operands)
        self.assertTrue(expected_values in actual)
Exemplo n.º 9
0
    def test_three_operands_result(self):
        from calculator import subtraction

        operands = "/9/12/-1"
        expected_result = "Difference  of operands: -2"
        actual = subtraction(operands)
        self.assertTrue(expected_result in actual)
Exemplo n.º 10
0
    def handle(self, handler_input):
        numbers = extract_numbers(handler_input)
        n1 = numbers["n1"]
        n2 = numbers["n2"]
        result = speakable(calc.subtraction(n1, n2))

        speak_output = f"The result of {n1} minus {n2} is {result} {continue_msg} "
        card = SimpleCard("My Calculator", str(result))

        return (
            handler_input.response_builder
                .speak(speak_output)
                .set_card(card)
                .set_should_end_session(False)
                .response
        )
Exemplo n.º 11
0
 def test_three_operands_values(self):
     from calculator import subtraction
     operands = '/9/12/-1'
     expected_values = "Operands provided: [9, 12, -1]"
     actual = subtraction(operands)
     self.assertTrue(expected_values in actual)
Exemplo n.º 12
0
 def test_one_operand_values(self):
     from calculator import subtraction
     operands = "5"
     expected_values = "Operands provided: [5]"
     actual = subtraction(operands)
     self.assertTrue(expected_values in actual)
Exemplo n.º 13
0
 def test_one_operand_result(self):
     from calculator import subtraction
     operands = "5"
     expected_result = "5"
     actual = subtraction(operands)
     self.assertTrue(expected_result in actual)
Exemplo n.º 14
0
 def test_subtraction(self):
     self.assertEqual(calculator.subtraction(2, 1), 1)
     self.assertEqual(calculator.subtraction(2, 1.5), .5)
     self.assertEqual(calculator.subtraction(5, 5), 0)
     self.assertEqual(calculator.subtraction(5, 8), -3)
Exemplo n.º 15
0
def test_subtraction():
    assert calculator.subtraction(1, 1) == 0
    assert calculator.subtraction(1, 2) == -1
    assert calculator.subtraction(-1, -4) == 3
    assert calculator.subtraction(-3, 1) == -4
 def test_subtraction_2(self):
     self.assertEqual(calculator.subtraction(-2, 4), -6)
Exemplo n.º 17
0
 def test_subtraction(self):
     assert 1 == calculator.subtraction(4, 3)
import calculator

user_choice = input("What operation do you want to perform: 1 - addition, 2 - subtraction, 3 - multiplication or 4 - division? ")
a = float(input("Enter the value a: "))
b = float(input("Enter the value b: "))

if user_choice == "1":
    print(calculator.addition(a, b))
elif user_choice == "2":
    print(calculator.subtraction(a, b))
elif user_choice == "3":
    print(calculator.multiplication(a, b))
elif user_choice == "4":
    print(calculator.division(a, b))
else:
    print("Incorrect value!")
Exemplo n.º 19
0
 def test_invalidSubtraction(self):
     self.assertEqual(subtraction(5, "bad input"), None)
Exemplo n.º 20
0
 def test_subtraction(self):
     self.assertEqual(subtraction(3, 2), 1)
Exemplo n.º 21
0
 def test_subtractionNegative(self):
     self.assertEqual(subtraction(3, -2), 5)
Exemplo n.º 22
0
 def test_4sub(self):
     result = calculator.subtraction(1999, 1999)
     self.assertEqual(result, 0)
Exemplo n.º 23
0
 def test_3sub(self):
     result = calculator.subtraction(3, 4)
     self.assertEqual(result, -1)
Exemplo n.º 24
0
 def test_subtraction(self):
     result = subtraction(50, 25)
     self.assertEqual(result, 25)
Exemplo n.º 25
0
 def test_three_operands_result(self):
     from calculator import subtraction
     operands = '/9/12/-1'
     expected_result = "Difference  of operands: -2"
     actual = subtraction(operands)
     self.assertTrue(expected_result in actual)
 def test_subtraction_3(self):
     self.assertEqual(calculator.subtraction(25.5, 10.5), 15.0)
Exemplo n.º 27
0
 def subtract(m, n):
     return c.subtraction(m, n)
Exemplo n.º 28
0
''' Sample custom modules / importing modules '''
import calculator as calc

print(calc.subtraction(12, 4))
 def test_subtraction_1(self):
     self.assertEqual(calculator.subtraction(10, 3), 7)
 def test_substraction(self):
     self.assertEqual(calculator.subtraction(2,1),1.0)
     self.assertEqual(calculator.subtraction(1,2),-1.0)
Exemplo n.º 31
0
 def testSub4 (self):
     self.assertEqual(subtraction('String', 3.5), 'Must be non string input')
Exemplo n.º 32
0
from calculator import addition, subtraction, multipication, division

while True:
    try:
        first = int(input("First Number: "))
        operand = input("Would you like to +, -, * or / ? ")
        second = int(input("Second Number: "))

        if operand == "+":
            addition(first, second)
            break
        elif operand == "-":
            subtraction(first, second)
            break
        elif operand == "*":
            multipication(first, second)
            break
        elif operand == "/":
            division(first, second)
            break
        else:
            print("Please enter a valid operand.")
    except ValueError:
        print("Please enter numbers only!")

quit = input("To quit the program, please press q then hit enter.").lower()
if quit == "q":
    import sys
    sys.exit(0)
Exemplo n.º 33
0
 def test_subtractionFloat(self):
     self.assertAlmostEqual(subtraction(3, -0.5), 3.5)
 def test_substraction(self):
     self.assertEqual(calculator.subtraction(6, 3), 3.0)
     self.assertEqual(calculator.subtraction(1, 2), -1.0)
     self.assertEqual(calculator.subtraction(4, 8), -4.0)
     self.assertEqual(calculator.subtraction(9, 3), 6.0)