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 Rotation(object):
def is_substring(self, s1, s2):
# TODO: Implement me
pass
def is_rotation(self, s1, s2):
# TODO: Implement me
# Call is_substring only once
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_rotation.py
import unittest
class TestRotation(unittest.TestCase):
def test_rotation(self):
rotation = Rotation()
self.assertEqual(rotation.is_rotation('o', 'oo'), False)
self.assertEqual(rotation.is_rotation(None, 'foo'), False)
self.assertEqual(rotation.is_rotation('', 'foo'), False)
self.assertEqual(rotation.is_rotation('', ''), True)
self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
print('Success: test_rotation')
def main():
test = TestRotation()
test.test_rotation()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.