forked from uchicago-cs/python-practice-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_cubes.py
94 lines (65 loc) · 2.01 KB
/
sum_cubes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def sum_cubes(n):
"""
Recursively calculates the sum of the first n positive cubes.
Input:
n: positive integer.
Returns: (integer) the value of the sum 1^3 + 2^3 + ... + n^3.
This function may not use any loops or list comprehensions.
"""
pass
#############################################################
### ###
### Testing code. ###
### !!! DO NOT MODIFY ANY CODE BELOW THIS POINT !!! ###
### ###
#############################################################
import sys
sys.path.append('../')
import test_utils as utils
def do_test_sum_cubes(n):
recreate_msg = utils.gen_recreate_msg('sum_cubes', n)
actual = sum_cubes(n)
expected = sum(n ** 3 for n in range(n + 1))
utils.check_none(actual, recreate_msg)
utils.check_type(actual, expected, recreate_msg)
utils.check_equals(actual, expected, recreate_msg)
def test_sum_cubes_1():
do_test_sum_cubes(1)
def test_sum_cubes_2():
do_test_sum_cubes(2)
def test_sum_cubes_3():
do_test_sum_cubes(3)
def test_sum_cubes_4():
do_test_sum_cubes(4)
def test_sum_cubes_5():
do_test_sum_cubes(5)
def test_sum_cubes_6():
do_test_sum_cubes(6)
def test_sum_cubes_7():
do_test_sum_cubes(7)
def test_sum_cubes_8():
do_test_sum_cubes(8)
def test_sum_cubes_9():
do_test_sum_cubes(9)
def test_sum_cubes_10():
do_test_sum_cubes(10)
def test_sum_cubes_11():
do_test_sum_cubes(15)
def test_sum_cubes_12():
do_test_sum_cubes(19)
def test_sum_cubes_13():
do_test_sum_cubes(24)
def test_sum_cubes_14():
do_test_sum_cubes(30)
def test_sum_cubes_15():
do_test_sum_cubes(31)
def test_sum_cubes_16():
do_test_sum_cubes(36)
def test_sum_cubes_17():
do_test_sum_cubes(42)
def test_sum_cubes_18():
do_test_sum_cubes(50)
def test_sum_cubes_19():
do_test_sum_cubes(81)
def test_sum_cubes_20():
do_test_sum_cubes(100)