Skip to content

Commit ceeeaac

Browse files
committed
test arrcsv
1 parent 41a1b86 commit ceeeaac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_arrcsv.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
from test import support
3+
from arrcsv import arr_to_csv
4+
5+
class TestArrayConvertsToCSV(unittest.TestCase):
6+
def test_1d_array_converts_to_csv(self):
7+
arr = [1, 2, 3, 4, 5, 6]
8+
csv = arr_to_csv(arr)
9+
self.assertEqual(csv, '1,2,3,4,5,6')
10+
11+
def test_2d_array_converts_to_csv(self):
12+
arr = [[1, 2, 3], [4, 5, 6]]
13+
csv = arr_to_csv(arr)
14+
self.assertEqual(csv, '1,2,3\n4,5,6')
15+
16+
def test_3d_array_converts_to_csv(self):
17+
arr = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
18+
csv = arr_to_csv(arr)
19+
self.assertEqual(csv, '1,2,3\n4,5,6\n7,8,9\n10,11,12')
20+
21+
class TestThrowsErrorOnInvalidArray(unittest.TestCase):
22+
def test_throws_error_on_invalid_array(self):
23+
with self.assertRaises(ValueError):
24+
arr = [[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]]
25+
arr_to_csv(arr)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

0 commit comments

Comments
 (0)