-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Rotational Cipher: Exercise Added #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e3b3198
say: Reorder test cases
behrtam 1622650
dibs: I will implement exercise Rotational Cipher
krapes d1b2144
rotationa_cipher: Completed test and example
krapes 3e78e94
rotational_cipher: Prepared and commited rotational_cipher.py
krapes abba798
rotational_cipher: Added excercise to config.json
krapes 86b35f6
rotational_cipher: Cleaned up formatting to meet standards
krapes 9b5407e
rotational_cipher: Streamlined example.py processes
krapes a0e8c02
rotational_cipher: Removed doc string
krapes 8d2c1fb
rotational_cipher: Updated test cases to comply with canonical test data
krapes e38cccb
rotational_cipher: Cleaned formatting to meet standards
krapes 94e36a2
rotational_cipher: Deleted erroneous file and moved import statements…
krapes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from string import ascii_lowercase as alpha_lower | ||
from string import ascii_uppercase as alpha_upper | ||
ALPHA_LEN = len(alpha_lower) | ||
|
||
|
||
def rotate(message, key): | ||
coded_message = "" | ||
for char in message: | ||
if char in alpha_lower: | ||
char = alpha_lower[(alpha_lower.index(char) + key) % ALPHA_LEN] | ||
elif char in alpha_upper: | ||
char = alpha_upper[(alpha_upper.index(char) + key) % ALPHA_LEN] | ||
coded_message += char | ||
return coded_message |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def rotate(): | ||
pass |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import unittest | ||
|
||
import rotational_cipher | ||
|
||
|
||
class RotationalCipher(unittest.TestCase): | ||
def test_rotate_a_by_1(self): | ||
self.assertEqual(rotational_cipher.rotate('a', 1), 'b') | ||
|
||
def test_rotate_a_by_26(self): | ||
self.assertEqual(rotational_cipher.rotate('a', 26), 'a') | ||
|
||
def test_rotate_a_by_0(self): | ||
self.assertEqual(rotational_cipher.rotate('a', 0), 'a') | ||
|
||
def test_rotate_m_by_13(self): | ||
self.assertEqual(rotational_cipher.rotate('m', 13), 'z') | ||
|
||
def test_rotate_n_by_13_with_wrap_around_alphabet(self): | ||
self.assertEqual(rotational_cipher.rotate('n', 13), 'a') | ||
|
||
def test_rotate_capital_letters(self): | ||
self.assertEqual(rotational_cipher.rotate('OMG', 5), 'TRL') | ||
|
||
def test_rotate_spaces(self): | ||
self.assertEqual(rotational_cipher.rotate('O M G', 5), | ||
'T R L') | ||
|
||
def test_rotate_numbers(self): | ||
self.assertEqual( | ||
rotational_cipher.rotate( | ||
'Testing 1 2 3 testing', | ||
4), | ||
'Xiwxmrk 1 2 3 xiwxmrk') | ||
|
||
def test_rotate_punctuation(self): | ||
self.assertEqual( | ||
rotational_cipher.rotate( | ||
"Let's eat, Grandma!", | ||
21), | ||
"Gzo'n zvo, Bmviyhv!") | ||
|
||
def test_rotate_all_letters(self): | ||
self.assertEqual( | ||
rotational_cipher.rotate( | ||
"The quick brown fox jumps" | ||
" over the lazy dog.", | ||
13), | ||
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to stick to the canonical test data provided in the
x-common
repository.If you are missing a test case that would make sense for all tracks, than it would be best to also add it there.
If you think we need an additional test case that would be python specific it would be good to mark those with a comment (
# additional track specific tests
) to make it easy to compare it against the common test cases.