-
-
Notifications
You must be signed in to change notification settings - Fork 48.9k
Add tests without modifying code #10740
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
Changes from 4 commits
c414518
41fffa1
ff894a8
6aa37f2
16d377e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,7 +4,17 @@ | |||
class Onepad: | ||||
@staticmethod | ||||
def encrypt(text: str) -> tuple[list[int], list[int]]: | ||||
"""Function to encrypt text using pseudo-random numbers""" | ||||
""" | ||||
Function to encrypt text using pseudo-random numbers | ||||
>>> Onepad().encrypt("") | ||||
([], []) | ||||
>>> random.seed(1) | ||||
>>> Onepad().encrypt(" ") | ||||
([6969], [69]) | ||||
>>> random.seed(1) | ||||
>>> Onepad().encrypt("Hello") | ||||
([9729, 114756, 4653, 31309, 10492], [69, 292, 33, 131, 61]) | ||||
""" | ||||
plain = [ord(i) for i in text] | ||||
key = [] | ||||
cipher = [] | ||||
|
@@ -17,7 +27,21 @@ def encrypt(text: str) -> tuple[list[int], list[int]]: | |||
|
||||
@staticmethod | ||||
def decrypt(cipher: list[int], key: list[int]) -> str: | ||||
"""Function to decrypt text using pseudo-random numbers.""" | ||||
""" | ||||
Function to decrypt text using pseudo-random numbers. | ||||
>>> Onepad().decrypt([], []) | ||||
'' | ||||
>>> Onepad().decrypt([35], []) | ||||
'' | ||||
>>> Onepad().decrypt([], [35]) | ||||
Traceback (most recent call last): | ||||
... | ||||
IndexError: list index out of range | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,23 @@ | |||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def res(x, y): | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
Reduces large number to a more manageable number | ||||||||||||||||||||||||||||||||||||||||
>>> res(5, 7) | ||||||||||||||||||||||||||||||||||||||||
4.892790030352132 | ||||||||||||||||||||||||||||||||||||||||
>>> res(0, 5) | ||||||||||||||||||||||||||||||||||||||||
0 | ||||||||||||||||||||||||||||||||||||||||
>>> res(3, 0) | ||||||||||||||||||||||||||||||||||||||||
1 | ||||||||||||||||||||||||||||||||||||||||
>>> res(-1, 5) | ||||||||||||||||||||||||||||||||||||||||
Traceback (most recent call last): | ||||||||||||||||||||||||||||||||||||||||
... | ||||||||||||||||||||||||||||||||||||||||
ValueError: math domain error | ||||||||||||||||||||||||||||||||||||||||
|
>>> res(0, 5) | |
0 | |
>>> res(3, 0) | |
1 | |
>>> res(-1, 5) | |
Traceback (most recent call last): | |
... | |
ValueError: math domain error | |
>>> res(0, 5) | |
0 | |
>>> res(3, 0) | |
1 | |
>>> res(-1, 5) | |
Traceback (most recent call last): | |
... | |
ValueError: math domain error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
def get_word_pattern(word: str) -> str: | ||
""" | ||
Returns numerical pattern of character appearances in given word | ||
>>> get_word_pattern() | ||
Traceback (most recent call last): | ||
... | ||
TypeError: get_word_pattern() missing 1 required positional argument: 'word' | ||
>>> get_word_pattern("") | ||
'' | ||
>>> get_word_pattern(" ") | ||
'0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put the tests that work correctly first and then afterward the ones that raise exceptions. Also, please add: |
||
>>> get_word_pattern("pattern") | ||
'0.1.2.2.3.4.5' | ||
>>> get_word_pattern("word pattern") | ||
|
Uh oh!
There was an error while loading. Please reload this page.