Created
December 14, 2016 19:06
-
-
Save serashioda/a77ae3d0b13c341cc2d6c203e4ab639b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Test the rotation module.""" | |
def rotation(str1, str2): | |
"""Check if str1 is a rotation of str2.""" | |
for n in range (len(str1)): | |
str3 = str1[-n:] + str1[:-n] | |
if str2 == str3: | |
return True | |
return False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Tests for rotation module.""" | |
import pytest | |
TEST_TABLE = [ | |
["abcd", "cdab", True], | |
["abcd", "cdabe", False] | |
@pytest.mark.parametrize("str1, str2, result", TEST_TABLE) | |
def test_rotations(str1, str2, result, Test_TABLE) | |
"""Test the rotation function.""" | |
from rotation import rotation | |
assert rotation(str1, str2) == result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is actually pretty good. And it works! You could also just shortcut the entire loop process and have