-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_join.py
37 lines (29 loc) · 1.66 KB
/
test_join.py
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
35
36
37
from arrayutilities import Arr
import unittest
class TestArr(unittest.TestCase):
def test_join_with_glue_only(self):
result = Arr.join(['apple', 'banana', 'cherry'], ', ')
self.assertEqual(result, 'apple, banana, cherry', "Should join items with only glue")
def test_join_with_final_glue(self):
result = Arr.join(['apple', 'banana', 'cherry'], ', ', ', and ')
self.assertEqual(result, 'apple, banana, and cherry', "Should join items with a final glue before the last item")
def test_join_single_item(self):
result = Arr.join(['apple'], ', ', ', and ')
self.assertEqual(result, 'apple', "Should handle single item lists without adding glue")
def test_join_no_items(self):
result = Arr.join([], ', ', ', and ')
self.assertEqual(result, '', "Should return an empty string for empty list")
def test_join_no_items_no_glues(self):
result = Arr.join([], ', ')
self.assertEqual(result, '', "Should return an empty string for empty list with only primary glue")
def test_join_two_items_with_final_glue(self):
result = Arr.join(['apple', 'banana'], ', ', ', and ')
self.assertEqual(result, 'apple, and banana', "Should join two items using the final glue")
def test_join_with_numeric_items(self):
result = Arr.join([1, 2, 3], '-', '-')
self.assertEqual(result, '1-2-3', "Should join numeric items, converting them to strings")
def test_join_with_one_numeric_item(self):
result = Arr.join([1], '-', '-')
self.assertEqual(result, '1', "Should join numeric items, converting them to strings")
if __name__ == '__main__':
unittest.main()