mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
29 lines
772 B
Python
29 lines
772 B
Python
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() |