Skip to content

Commit 8bf35a0

Browse files
Merge pull request #9 from JordanWelsman/develop
New functions created and implemented. Test functions written. All tests pass. To-do list complete. Merging now.
2 parents 2de8d64 + 31eb369 commit 8bf35a0

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

mathplug/mathplug.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# absolute
2+
def absolute(arg):
3+
"""Returns the absolute value of the argument."""
4+
result = 0
5+
if arg < 1:
6+
result = (arg * -1)
7+
else: result = arg
8+
return result
9+
10+
111
# addition
212
def add(*arg):
313
"""Returns sum of numbers passed in."""
@@ -7,6 +17,12 @@ def add(*arg):
717
return total
818

919

20+
# cube
21+
def cube(arg):
22+
"""Returns the argument multiplied by itself, multiplied by itself again."""
23+
return arg * arg * arg
24+
25+
1026
# division
1127
def divide(*arg):
1228
"""Returns result of division of other arguments on first argument."""
@@ -21,6 +37,21 @@ def divide(*arg):
2137
return result
2238

2339

40+
# exponent
41+
def exponent(number, exponent):
42+
"""Returns the first argument raised to the second argument."""
43+
result = number
44+
if exponent == 0:
45+
result = number
46+
elif exponent >= 1:
47+
for i in range(exponent - 1):
48+
result *= number
49+
print(result)
50+
else:
51+
raise AssertionError("Exponent is invalid.")
52+
return result
53+
54+
2455
# Hello, World!
2556
def hello_world(name=None):
2657
"""Greets the caller."""
@@ -61,4 +92,9 @@ def subtract(*arg):
6192
subtractor = 0
6293
for n in arg:
6394
subtractor += n
64-
return (arg[0] - (subtractor-arg[0]))
95+
return (arg[0] - (subtractor-arg[0]))
96+
97+
98+
# new function test
99+
# def test():
100+
# assert exponent(1, 4) == 1

mathplug/test_mathplug.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
# import module
1+
# module import
22
from mathplug import mathplug as t
33

44

5+
# absolute()
6+
def test_absolute():
7+
assert t.absolute(45) == 45
8+
9+
def test_absolute_zero():
10+
assert t.absolute(0) == 0
11+
12+
def test_absolute_negative():
13+
assert t.absolute(-6) == 6
14+
15+
def test_absolute_wrong():
16+
assert t.absolute(20) != 10
17+
18+
519
# add()
620
def test_add():
721
assert t.add(10, 20) == 30
@@ -13,6 +27,17 @@ def test_add_wrong():
1327
assert t.add(30, 50) != 70
1428

1529

30+
# cube()
31+
def test_cube():
32+
assert t.cube(5) == 125
33+
34+
def test_cube_negative():
35+
assert t.cube(-3) == -27
36+
37+
def test_cube_wrong():
38+
assert t.cube(7) != 21
39+
40+
1641
# divide()
1742
def test_divide():
1843
assert t.divide(10, 20) == 2
@@ -24,6 +49,20 @@ def test_divide_wrong():
2449
assert t.divide(30, 60) != 3
2550

2651

52+
# exponent()
53+
def test_exponent():
54+
assert t.exponent(3, 2) == 9
55+
56+
def test_exponent():
57+
assert t.exponent(5, 0) == 5
58+
59+
def test_exponent_negative():
60+
assert t.exponent(-4, 3) == -64
61+
62+
def test_exponent_wrong():
63+
assert t.exponent(10, 3) != 30
64+
65+
2766
# hello_world()
2867
def test_hello_world():
2968
assert t.hello_world() == "Hello, World!"

0 commit comments

Comments
 (0)