-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathcsv-sort.py
37 lines (30 loc) · 951 Bytes
/
csv-sort.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 __future__ import print_function
import unittest
def csv_sort( string , console_out=True):
items=[x for x in string.split(',')]
items.sort()
if console_out:
print( ','.join(items) )
else:
return ','.join(items)
# Unit tests
class csv_sort_tests(unittest.TestCase):
def setUp(self):
self.stringOne = "33,44,55,11,22"
self.stringTwo = "a,f,d,z,y,e"
self.stringEdge = ""
self.stringEdgeTwo = "z,z,z,z,z,z,z"
def test_csv_sort_one(self):
self.assertEqual(
csv_sort(self.stringOne, False), "11,22,33,44,55"
)
self.assertEqual(
csv_sort(self.stringTwo, False), "a,d,e,f,y,z"
)
self.assertEqual( csv_sort(self.stringEdge, False), "" )
self.assertEqual(
csv_sort(self.stringEdgeTwo, False), "z,z,z,z,z,z,z"
)
if __name__ == '__main__':
print("Tests started")
unittest.main()