-
Notifications
You must be signed in to change notification settings - Fork 95
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
Jesus 1.1 - is_unique [Python] #44
base: master
Are you sure you want to change the base?
Conversation
import unittest | ||
|
||
|
||
def is_unique(s: str) -> bool: |
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.
Can you add a docstring? In the docstring, please document what the runtime+space complexity is.
import unittest | ||
|
||
|
||
def is_unique(s: str) -> bool: |
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.
good job on adding typing information! :D
class TestIsUnique(unittest.TestCase): | ||
|
||
def test_is_unique(self): | ||
self.assertEqual(is_unique('aaaaa'), False) |
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.
there are better assertions you can use: https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertTrue
self.assertEqual(is_unique('aaaaa'), False) | |
self.assertFalse(is_unique('aaaaa')) |
same below
@@ -0,0 +1,22 @@ | |||
import unittest |
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.
Would it be possible for you to add a module docstring with the problem statement? Not all (volunteer!) reviewers have a copy of the book.
|
||
class TestIsUnique(unittest.TestCase): | ||
|
||
def test_is_unique(self): |
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.
this might be okay for now, but for more complex tests, Golang has this wonderful pattern called table driven tests, where you can restructure the code the following way:
for s, expected in [
('aaaaa', False),
('abc', True),
...
('a', True),
]:
self.assertEqual(is_unique(s), expected, msg=s)
to cut down on repetition.
for even further de-duplication, you can split the test in positive and negative tests:
def test_is_unique(self):
for s in [
'abc',
....
'',
]:
self.assertTrue(is_unique(s), msg=s)
def test_is_not_unique(self):
for s in [
'aaaaa',
....
'abcda',
]:
self.assertFalse(is_unique(s), msg=s)
No description provided.