Sie sind in der Lage, mit PyCharm Unit Tests auf der Basis von pytest
zu erstellen und auszuführen.
calculator.py
via PyCharm.add
und klicken Sie <ctrl+shift+t> um einen Unit Test mit der Methode test_add
dafür zu erstellen. test_calculator.py
unten.sub
, div
, mult
, root
und sqr
add
, sub
, div
, mult
die Rechnungen mit den Zahlenwerten (10,5), (-10,5), (10,-5) und (-10,-5) ausgeführt werden.Commiten
und Pushen
Sie Ihre Lösung auf Github falls Sie mit Github arbeitenimport math def add(num1, num2): """ Addition of two numbers :param num1: number 1 for calculation :param num2: number 2 for calculation :return: result of calculation """ return num1 + num2 def sub(num1, num2): """ Substracts two numbers :param num1: number 1 for calculation :param num2: number 2 for calculation :return: result of calculation """ return num1 - num2 def mul(num1, num2): """ multiply of two numbers :param num1: number 1 for calculation :param num2: number 2 for calculation :return: result of calculation """ return num1 * num2 def div(num1, num2): """ division of two numbers :param num1: number 1 for calculation :param num2: number 2 for calculation :return: result of calculation """ return num1 / num2 def sqr(num1): """ Squares two numbers :param num1: number to square :return: result of calculation """ return num1*num1 def root(num1): """ return the root of a number :param num1: number to get the root of :return: result of calculation """ return math.sqrt(num1) def main(): result_add = add(5, 5.5) result_div = div(10,3) result_mul = mul(3,3) result_sub = sub(10,4.4) result_sqr = sqr(23) result_root = root(81) print(result_add) print(result_div) print(result_mul) print(result_sub) print(result_sqr) print(result_root) if __name__ == '__main__': main()
import calculator def test_add(): calculator.add(10, 5) assert calculator.add(10, 5) == 15