Added replace char challenge.

This commit is contained in:
Donne Martin
2015-07-03 19:56:54 -04:00
parent fb7de503af
commit ac42b882bb
3 changed files with 255 additions and 19 deletions

View 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()