Conversation
| import unittest | ||
|
|
||
|
|
||
| def is_unique(s: str) -> bool: |
There was a problem hiding this comment.
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.
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.
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.
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.
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.