-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_str_to_list.py
More file actions
34 lines (26 loc) · 1.59 KB
/
test_str_to_list.py
File metadata and controls
34 lines (26 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from arrayutilities import Arr
import unittest
class TestArr(unittest.TestCase):
def test_list_to_array_with_default_separator(self):
result = Arr.str_to_list("apple, banana, cherry")
self.assertEqual(result, ["apple", "banana", "cherry"], "Should convert string with default separator to list")
def test_list_to_array_with_custom_separator(self):
result = Arr.str_to_list("apple|banana|cherry", sep="|")
self.assertEqual(result, ["apple", "banana", "cherry"], "Should convert string with custom separator to list")
def test_list_to_array_empty_string(self):
result = Arr.str_to_list("")
self.assertEqual(result, [], "Should return an empty list for empty string")
def test_list_to_array_with_empty_elements(self):
result = Arr.str_to_list("apple,,banana,")
self.assertEqual(result, ["apple", "banana"], "Should remove empty elements from string")
def test_list_to_array_list_input(self):
result = Arr.str_to_list(["apple", "banana", "cherry"])
self.assertEqual(result, ["apple", "banana", "cherry"], "Should return the input list unchanged")
def test_list_to_array_whitespace_elements(self):
result = Arr.str_to_list(" apple , banana , cherry ")
self.assertEqual(result, ["apple", "banana", "cherry"], "Should remove leading/trailing whitespace from elements")
def test_list_to_array_whitespace_string(self):
result = Arr.str_to_list(" ")
self.assertEqual(result, [], "Should return an empty list for string with only whitespace")
if __name__ == '__main__':
unittest.main()