File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,3 +17,7 @@ def rotate(s, k):
1717 return long_string [k :k + len (s )]
1818 else :
1919 return long_string [k - len (s ):k ]
20+
21+ def rotate_alt (string , k ):
22+ k = k % len (string )
23+ return string [k :] + string [:k ]
Original file line number Diff line number Diff line change @@ -225,6 +225,12 @@ def test_rotate(self):
225225 self .assertEqual ("hello" , rotate ("hello" , 5 ))
226226 self .assertEqual ("elloh" , rotate ("hello" , 6 ))
227227 self .assertEqual ("llohe" , rotate ("hello" , 7 ))
228+
229+ def test_rotate_alt (self ):
230+ self .assertEqual ("llohe" , rotate_alt ("hello" , 2 ))
231+ self .assertEqual ("hello" , rotate_alt ("hello" , 5 ))
232+ self .assertEqual ("elloh" , rotate_alt ("hello" , 6 ))
233+ self .assertEqual ("llohe" , rotate_alt ("hello" , 7 ))
228234
229235
230236class TestLicenseNumber (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments