Skip to content

Commit

Permalink
Merge pull request #9 from JordanWelsman/develop
Browse files Browse the repository at this point in the history
New functions created and implemented. Test functions written. All tests pass. To-do list complete. Merging now.
  • Loading branch information
JordanWelsman authored Oct 26, 2022
2 parents 2de8d64 + 31eb369 commit 8bf35a0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
38 changes: 37 additions & 1 deletion mathplug/mathplug.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand Down Expand Up @@ -61,4 +92,9 @@ def subtract(*arg):
subtractor = 0
for n in arg:
subtractor += n
return (arg[0] - (subtractor-arg[0]))
return (arg[0] - (subtractor-arg[0]))


# new function test
# def test():
# assert exponent(1, 4) == 1
41 changes: 40 additions & 1 deletion mathplug/test_mathplug.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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!"
Expand Down

0 comments on commit 8bf35a0

Please sign in to comment.