This notebook was prepared by [Thunder Shiviah](https://github.com/ThunderShiviah). Source and license info is on [GitHub](https://github.com/ThunderShiviah/code_guild).

Solution Notebook

Problem: Implement foo(val), which returns val

Constraints

  • Does foo do anything else?
    • No

Test Cases

  • foo(val) -> val

Algorithm

Return the input, val

Complexity:

  • Time: O(1)
  • Space: O(1)

Code


In [1]:
def foo(val):
    return val

Unit Test


In [2]:
%%writefile test_foo.py
from nose.tools import assert_equal


class TestFoo(object):

    def test_foo(self):
        assert_equal(foo(None), None)
        assert_equal(foo(0), 0)
        assert_equal(foo('bar'), 'bar')
        print('Success: test_foo')


def main():
    test = TestFoo()
    test.test_foo()


if __name__ == '__main__':
    main()


Overwriting test_foo.py

In [3]:
%run -i test_foo.py


Success: test_foo