This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).
In [1]:
def is_substring(s1, s2):
return s1 in s2
def is_rotation(s1, s2):
if s1 is None or s2 is None:
return False
if len(s1) != len(s2):
return False
s3 = s1 + s1
return is_substring(s2, s3)
In [2]:
%%writefile test_rotation.py
from nose.tools import assert_equal
class TestRotation(object):
def test_rotation(self):
assert_equal(is_rotation('o', 'oo'), False)
assert_equal(is_rotation(None, 'foo'), False)
assert_equal(is_rotation('', 'foo'), False)
assert_equal(is_rotation('', ''), True)
assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)
print('Success: test_rotation')
def main():
test = TestRotation()
test.test_rotation()
if __name__ == '__main__':
main()
In [3]:
%run -i test_rotation.py