This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Solution(object):
def __init__(self, upper_limit=100):
# TODO: Implement me
pass
def insert(self, val):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_math_ops.py
import unittest
class TestMathOps(unittest.TestCase):
def test_math_ops(self):
solution = Solution()
self.assertRaises(TypeError, solution.insert, None)
solution.insert(5)
solution.insert(2)
solution.insert(7)
solution.insert(9)
solution.insert(9)
solution.insert(2)
solution.insert(9)
solution.insert(4)
solution.insert(3)
solution.insert(3)
solution.insert(2)
self.assertEqual(solution.max, 9)
self.assertEqual(solution.min, 2)
self.assertEqual(solution.mean, 5)
self.assertTrue(solution.mode in (2, 9))
print('Success: test_math_ops')
def main():
test = TestMathOps()
test.test_math_ops()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.