Ejemplo n.º 1
0
    def test_addition(self):
        # 1. setup test data
        num1 = 100
        num2 = 300

        # 2. call the method you want to test
        result = addition(num1, num2)

        # 3. verify the result
        self.assertEqual(result, 400)  # verify the result
Ejemplo n.º 2
0
    def test_with_negative_numbers3(self):
        # 1. setup test data
        num1 = -100
        num2 = 500

        # 2. call the method you want to test
        result = addition(num1, num2)

        # 3. verify the result
        self.assertEqual(result, 400)  # verify the result
Ejemplo n.º 3
0
def add():
    number1 = request.args.get("number1", None)
    number2 = request.args.get("number2", None)
    response = {}

    if not number1 or not number2:
        response["ERROR"] = "please send two numbers."
    else:
        result = calc.addition(int(number1), int(number2))
        response["MESSAGE"] = f"{number1} + {number2}"
        response["RESULTBINARY"] = f"{result[1]}"
        response["RESULTDECIMAL"] = f"{result[0]}"

    return jsonify(response)
 def test_add(self):
     self.assertEqual(calc.addition(10,5),15)
 def test_addition(self):
  result = calc.addition(4,3)
  self.assertEqual(result, 7)
Ejemplo n.º 6
0
 def test_addition(self):
     tests = [(0, 0, 0), (1, 1, 2), (45636, 3563, 49199)]
     self.assertTrue(all([calc.addition(x, y) == a for x,y,a in tests]))
Ejemplo n.º 7
0
def add():
    add = addition(5,6) # passing parameter to addtion function written in calc.py which already imported
    return add
Ejemplo n.º 8
0
    def test_sum(self):

        x = calc.addition(3,6)
        self.assertEqual(9,x)
Ejemplo n.º 9
0
 def test_add(self):
     self.assertEqual(calc.addition(10, 5), 15)
     self.assertEqual(calc.substraction(5, 10), -5)
     self.assertEqual(calc.multiplication(5, 10), 50)
     self.assertEqual(calc.division(5, 10), .5)
Ejemplo n.º 10
0
from calc import addition, subtraction, division, multiplication, power

print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Power")
# Take input from the user
choice = input("Enter choice(1/2/3/4/5):")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if choice == '1':
    print(num1, "+", num2, " = ", addition(num1, num2))

elif choice == '2':
    print(num1, "-", num2, " = ", subtraction(num1, num2))

elif choice == '3':
    print(num1, "*", num2, " = ", multiplication(num1, num2))

elif choice == '4':
    print(num1, "/", num2, " = ", division(num1, num2))

elif choice == '5':
    print(num1, "^", num2, " = ", power(num1, num2))

############### The Exercises (7- 9) and Warm up exercises (7 & 8) are in the Numpy_Exercise.py file ##################
Ejemplo n.º 11
0
from calc import addition

print("outside if statement", __name__)
if __name__ == '__main__':
    print(addition(100, 200))
    print("inside if statement", __name__)

Ejemplo n.º 12
0
 def test_addition(self):
     self.assertEqual(calc.addition(5, 5), 10)
     self.assertEqual(calc.addition(-3, 3), 0)
     self.assertEqual(calc.addition(-5, -5), -10)
Ejemplo n.º 13
0
 def test_addition(self):
     result = calc.addition(5, 4)
     self.assertEqual(result, 9)
Ejemplo n.º 14
0
 def test_add(self):
     self.assertEqual(calc.addition(10, 5), 15)
     self.assertEqual(calc.addition(-1, 1), 0)
     self.assertEqual(calc.addition(-1, -1), -2)
Ejemplo n.º 15
0
 def test_addition(self):
     self.assertEqual(calc.addition(10, 5), 15)
     self.assertEqual(calc.addition(10, -10), 0)
     self.assertEqual(calc.addition(-10, -10), -20)
Ejemplo n.º 16
0
            print(
                "Es ist ein Fehler aufgetreten! Bitte überprüfen Sie die Eingabe"
            )
    elif operator in ["log", "wurzel", "x²"]:
        try:
            zahl1 = int(input("Zahl: ").strip())
        except Exception as error:
            print(
                "Es ist ein Fehler aufgetreten! Bitte überprüfen Sie die Eingabe"
            )
    else:
        print(
            "Es ist ein Fehler aufgetreten! Bitte überprüfen Sie die Eingabe")

    if operator == "+":
        ergebnis = calc.addition(zahl1, zahl2)
        print("Das Ergebnis ist: ", str(ergebnis))
        calc.writefile(str(ergebnis))

    elif operator == "-":
        ergebnis = calc.subtraktion(zahl1, zahl2)
        print("Das Ergebnis ist: ", str(ergebnis))
        calc.writefile(str(ergebnis))
    elif operator == "*":
        ergebnis = calc.multiplikation(zahl1, zahl2)
        print("Das Ergebnis ist: ", str(ergebnis))
        calc.writefile(str(ergebnis))
    elif operator == "/":
        ergebnis = calc.division(zahl1, zahl2)
        print("Das Ergebnis ist: ", str(ergebnis))
        calc.writefile(str(ergebnis))
Ejemplo n.º 17
0
When this file is either run or imported, nothing should be executed.

In your solutions file, import your new custom module. Write a function that accepts two
numbers representing the lengths of the sides of a right triangle. Using only the functions from
calculator.py, calculate and return the length of the hypotenuse of the triangle.

'''
import calc
from math import sqrt
#a^2 + b^2 = c^2

a2 = calc.products(2,2)
b2 = calc.products(3,3)

c = sqrt(calc.addition(a2, b2))
print(c)

'''

Problem 4.
The power set of a set A, denoted P(A) or 2^A, is the set of all subsets of A,
including the empty set ∅ and A itself. For example, the power set of the set
A = {a, b, c} is 2^A = {∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}.

Write a function that accepts an iterable A. Use an itertools function to compute
the power set of A as a list of sets (why couldn’t it be a set of sets in Python?).

'''

from itertools import chain, cycle, combinations, permutations
Ejemplo n.º 18
0
 def test_addition(self):
     self.assertEqual(calc.addition(2, 3), 5)
     self.assertEqual(calc.addition(0, 0), 0)
     self.assertEqual(calc.addition(7, 3), 10)
Ejemplo n.º 19
0
from calc import add as addition
print("Addition: ", addition(1, 2))