|
1 | 1 | from biocutils import show_as_cell |
| 2 | +import numpy |
2 | 3 |
|
3 | 4 |
|
4 | 5 | def test_show_as_cell(): |
5 | 6 | assert show_as_cell([1, 2, 3, 4], range(4)) == ["1", "2", "3", "4"] |
6 | 7 | assert show_as_cell([1, 2, 3, 4], [1, 3]) == ["2", "4"] |
| 8 | + |
| 9 | + assert show_as_cell(["abcdefghijklmnopqrstuvwxy", "abcdefghijklmnopqrstuvwxyz"], [0,1]) == ["abcdefghijklmnopqrstuvwxy", "abcdefghijklmnopqrst..."] |
| 10 | + assert show_as_cell(["abcdefghijkl\nmnopqrstuvwxyz", "abc\ndefghijklmnopqrstuvwxyz"], [0,1]) == ["abcdefghijkl...", "abc..."] |
| 11 | + |
| 12 | + |
| 13 | +def test_show_as_cell_numpy(): |
| 14 | + n1d = numpy.array([1,2,3,4,5]) |
| 15 | + assert show_as_cell(n1d, [0, 1, 4]) == ["1", "2", "5"] |
| 16 | + |
| 17 | + # Empty arrays are processed correctly. |
| 18 | + empty = numpy.ndarray((10, 0)) |
| 19 | + assert show_as_cell(empty, [0, 1, 4]) == ["[]", "[]", "[]"] |
| 20 | + empty = numpy.ndarray((10, 20, 0)) |
| 21 | + assert show_as_cell(empty, [0, 1, 2, 3]) == ["[]", "[]", "[]", "[]"] |
| 22 | + |
| 23 | + # Arrays where all other extents are 1 are processed correctly. |
| 24 | + n1col = numpy.array([1,2,3,4,5]).reshape((5, 1)) |
| 25 | + assert show_as_cell(n1col, [2, 3]) == ["[3]", "[4]"] |
| 26 | + n1col = numpy.array([1,2,3,4,5]).reshape((5, 1, 1)) |
| 27 | + assert show_as_cell(n1col, [1, 4]) == ["[[2]]", "[[5]]"] |
| 28 | + |
| 29 | + # Arrays other extents are > 1 are processed correctly. |
| 30 | + general = numpy.array([1,2,3,4,5,6]).reshape((3, 2)) |
| 31 | + assert show_as_cell(general, [0, 2]) == ["[1 2]", "[5 6]"] |
| 32 | + general = numpy.array([1,2,3,4,5,6]).reshape((3, 2, 1)) |
| 33 | + assert show_as_cell(general, [0, 2]) == ["[[1]...", "[[5]..."] |
0 commit comments