From f8286dcbab3f2522be52e7b5853e5f913cd55522 Mon Sep 17 00:00:00 2001 From: Jordan Welsman Date: Wed, 26 Oct 2022 00:01:58 -0500 Subject: [PATCH 1/2] Added functions for absolute, cube, and exponent. --- mathplug/mathplug.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mathplug/mathplug.py b/mathplug/mathplug.py index c4c82cf..eadacb4 100644 --- a/mathplug/mathplug.py +++ b/mathplug/mathplug.py @@ -1,3 +1,13 @@ +# absolute +def absolute(arg): + """Returns the absolute value of the argument.""" + result = 0 + if arg < 1: + result = (arg * -1) + else: result = arg + return result + + # addition def add(*arg): """Returns sum of numbers passed in.""" @@ -7,6 +17,12 @@ def add(*arg): return total +# cube +def cube(arg): + """Returns the argument multiplied by itself, multiplied by itself again.""" + return arg * arg * arg + + # division def divide(*arg): """Returns result of division of other arguments on first argument.""" @@ -21,6 +37,21 @@ def divide(*arg): return result +# exponent +def exponent(number, exponent): + """Returns the first argument raised to the second argument.""" + result = number + if exponent == 0: + result = number + elif exponent >= 1: + for i in range(exponent - 1): + result *= number + print(result) + else: + raise AssertionError("Exponent is invalid.") + return result + + # Hello, World! def hello_world(name=None): """Greets the caller.""" @@ -61,4 +92,9 @@ def subtract(*arg): subtractor = 0 for n in arg: subtractor += n - return (arg[0] - (subtractor-arg[0])) \ No newline at end of file + return (arg[0] - (subtractor-arg[0])) + + +# new function test +# def test(): + # assert exponent(1, 4) == 1 \ No newline at end of file From 31eb36982d9d110d227525a2180254f52a2dac14 Mon Sep 17 00:00:00 2001 From: Jordan Welsman Date: Wed, 26 Oct 2022 00:14:09 -0500 Subject: [PATCH 2/2] Added tests for new functions. All tests pass. --- mathplug/test_mathplug.py | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/mathplug/test_mathplug.py b/mathplug/test_mathplug.py index e1b4106..b7466e9 100644 --- a/mathplug/test_mathplug.py +++ b/mathplug/test_mathplug.py @@ -1,7 +1,21 @@ -# import module +# module import from mathplug import mathplug as t +# absolute() +def test_absolute(): + assert t.absolute(45) == 45 + +def test_absolute_zero(): + assert t.absolute(0) == 0 + +def test_absolute_negative(): + assert t.absolute(-6) == 6 + +def test_absolute_wrong(): + assert t.absolute(20) != 10 + + # add() def test_add(): assert t.add(10, 20) == 30 @@ -13,6 +27,17 @@ def test_add_wrong(): assert t.add(30, 50) != 70 +# cube() +def test_cube(): + assert t.cube(5) == 125 + +def test_cube_negative(): + assert t.cube(-3) == -27 + +def test_cube_wrong(): + assert t.cube(7) != 21 + + # divide() def test_divide(): assert t.divide(10, 20) == 2 @@ -24,6 +49,20 @@ def test_divide_wrong(): assert t.divide(30, 60) != 3 +# exponent() +def test_exponent(): + assert t.exponent(3, 2) == 9 + +def test_exponent(): + assert t.exponent(5, 0) == 5 + +def test_exponent_negative(): + assert t.exponent(-4, 3) == -64 + +def test_exponent_wrong(): + assert t.exponent(10, 3) != 30 + + # hello_world() def test_hello_world(): assert t.hello_world() == "Hello, World!"