46 lines
1.4 KiB
Python
Executable File
46 lines
1.4 KiB
Python
Executable File
# "Ручной" аналог функции split()
|
|
def split_string(string, separator):
|
|
result = []
|
|
element = ""
|
|
for c in range(len(string)):
|
|
if c != separator:
|
|
element = c
|
|
else:
|
|
c = ""
|
|
result.append(element)
|
|
return result
|
|
|
|
|
|
#################################################
|
|
def verifier(test_name, actual, expected):
|
|
print(test_name)
|
|
if actual != expected:
|
|
print("=======> FAILED! <=======")
|
|
print(f"Got value <{actual}>")
|
|
print(f"Expected value is <{expected}>")
|
|
else:
|
|
print("PASSED")
|
|
print()
|
|
|
|
|
|
test_string1 = "The World is not enough"
|
|
test_string2 = "Testing is key"
|
|
|
|
test_split1 = "1, 2, 3, 4, 5, 6, 7, 8, 9"
|
|
test_split2 = "1 2 3 4 5 6 7 8 9"
|
|
test_split3 = "bagahajemanbdneorijahdhrea4"
|
|
|
|
split_string_tests = [test_split1, test_split2, test_split3, test_string1, test_string2, '']
|
|
|
|
for i in range(len(split_string_tests)):
|
|
separator = ','
|
|
verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}",
|
|
split_string(split_string_tests[i], separator),
|
|
split_string_tests[i].split(separator))
|
|
|
|
for i in range(len(split_string_tests)):
|
|
separator = ' '
|
|
verifier(f"SPLIT_STRING (SEPARATOR='{separator}') TEST {i+1}",
|
|
split_string(split_string_tests[i], separator),
|
|
split_string_tests[i].split(separator))
|