Skip to content

Instantly share code, notes, and snippets.

@serashioda
Created December 14, 2016 19:06
Show Gist options
  • Save serashioda/a77ae3d0b13c341cc2d6c203e4ab639b to your computer and use it in GitHub Desktop.
Save serashioda/a77ae3d0b13c341cc2d6c203e4ab639b to your computer and use it in GitHub Desktop.
"""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
"""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
@nhuntwalker
Copy link

This is actually pretty good. And it works! You could also just shortcut the entire loop process and have

def rotation(str1, str2):
     return str1 in str2 + str2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment