mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 03:18:02 +00:00
Added replace char challenge.
This commit is contained in:
29
arrays_strings/replace_char/test_replace_char.py
Normal file
29
arrays_strings/replace_char/test_replace_char.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestReplace(object):
|
||||
|
||||
def test_replace_char(self, func):
|
||||
# | are used to satisfy the constraint that
|
||||
# there is enough space in the string to replace
|
||||
# ' ' with '%20'
|
||||
str0 = None
|
||||
str1 = bytearray(' ||')
|
||||
str2 = bytearray(' foo bar ||||||')
|
||||
str3 = bytearray('foo')
|
||||
func(str0, 0)
|
||||
func(str1, 1)
|
||||
func(str2, 9)
|
||||
func(str3, 3)
|
||||
assert_equal(str0, None)
|
||||
assert_equal(str1, '%20')
|
||||
assert_equal(str2, '%20foo%20bar%20')
|
||||
assert_equal(str3, 'foo')
|
||||
print('Success: test_replace_char')
|
||||
|
||||
def main():
|
||||
test = TestReplace()
|
||||
test.test_replace_char(encode_spaces)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user