|
6 | 6 |
|
7 | 7 | class CellTestCase(unittest.TestCase): |
8 | 8 |
|
| 9 | + # def test_instantiate_empty(self): |
| 10 | + # c = Cell() |
| 11 | + # a = np.asarray([]) |
| 12 | + # self.assertIsInstance(c, Cell) |
| 13 | + # self.assertListEqual(c.tolist(), a.tolist()) |
| 14 | + |
9 | 15 | def test_instantiate_empty(self): |
| 16 | + # Construct an empty cell array |
10 | 17 | c = Cell() |
11 | | - a = np.asarray([]) |
| 18 | + |
| 19 | + # Check proper construction |
12 | 20 | self.assertIsInstance(c, Cell) |
13 | | - self.assertListEqual(c.tolist(), a.tolist()) |
| 21 | + self.assertTupleEqual(c.shape, (0, 0)) |
| 22 | + |
| 23 | + # def test_instantiate_shape_1d(self): |
| 24 | + # c = Cell([3]) |
| 25 | + # self.assertIsInstance(c, Cell) |
| 26 | + # self.assertEqual(c.shape, (3,)) |
| 27 | + # self.assertTrue(all(x.shape == (0,) for x in c)) |
| 28 | + |
| 29 | + # def test_instantiate_empty_1d_shape_cell(self): |
| 30 | + # # Construct a 3x3 cell array ? |
| 31 | + # c = Cell(3) |
14 | 32 |
|
15 | | - def test_instantiate_shape_1d(self): |
16 | | - c = Cell([3]) |
| 33 | + # # Check proper construction |
| 34 | + # self.assertIsInstance(c, Cell) |
| 35 | + # self.assertTupleEqual(c.shape, (1, 3)) |
| 36 | + # self.assertTrue(all(isinstance(x, Array) for x in c.flat)) |
| 37 | + # self.assertTrue(all(x.shape == (0,) for x in c.flat)) |
| 38 | + |
| 39 | + def test_instantiate_empty_1d_row_cell(self): |
| 40 | + # Construct a 1x3 cell array |
| 41 | + c = Cell(1, 3) |
| 42 | + |
| 43 | + # Check proper construction |
17 | 44 | self.assertIsInstance(c, Cell) |
18 | | - self.assertEqual(c.shape, (3,)) |
19 | | - self.assertTrue(all(x.shape == (0,) for x in c)) |
| 45 | + self.assertTupleEqual(c.shape, (1, 3)) |
| 46 | + self.assertTrue(all(isinstance(x, Array) for x in c.flat)) |
| 47 | + self.assertTrue(all(x.shape == (0,) for x in c.flat)) |
20 | 48 |
|
21 | | - def test_instantiate_shape_2d(self): |
22 | | - c = Cell([3, 2]) |
| 49 | + def test_instantiate_empty_1d_col_cell(self): |
| 50 | + # Construct a 3x1 cell array |
| 51 | + c = Cell(3, 1) |
| 52 | + |
| 53 | + # Check proper construction |
23 | 54 | self.assertIsInstance(c, Cell) |
24 | | - self.assertEqual(c.shape, (3, 2)) |
| 55 | + self.assertTupleEqual(c.shape, (3, 1)) |
| 56 | + self.assertTrue(all(isinstance(x, Array) for x in c.flat)) |
25 | 57 | self.assertTrue(all(x.shape == (0,) for x in c.flat)) |
26 | 58 |
|
| 59 | + def test_instantiate_empty_2d_cell(self): |
| 60 | + # Construct a 3x2 cell array |
| 61 | + c = Cell(3, 2) |
| 62 | + |
| 63 | + # Check proper construction |
| 64 | + self.assertIsInstance(c, Cell) |
| 65 | + self.assertTupleEqual(c.shape, (3, 2)) |
| 66 | + self.assertTrue(all(isinstance(x, Array) for x in c.flat)) |
| 67 | + self.assertTrue(all(x.shape == (0,) for x in c.flat)) |
| 68 | + |
| 69 | + # def test_instantiate_shape_2d(self): |
| 70 | + # c = Cell([3, 2]) |
| 71 | + # self.assertIsInstance(c, Cell) |
| 72 | + # self.assertEqual(c.shape, (3, 2)) |
| 73 | + # self.assertTrue(all(x.shape == (0,) for x in c.flat)) |
| 74 | + |
27 | 75 | def test_instantiate_shape_order(self): |
28 | 76 | c = Cell([3, 2], order="C") |
29 | 77 | self.assertIsInstance(c, Cell) |
@@ -83,17 +131,106 @@ def test_cell1d_from_matlab(self): |
83 | 131 | c_python = Cell.from_any([1, 2, 3]) |
84 | 132 | self.assertListEqual(c_matlab.tolist(), c_python.tolist()) |
85 | 133 |
|
86 | | - def test_cell2d_from_matlab(self): |
87 | | - c_matlab = Runtime.call("eval", "{1, 2, 3; 4, 5, 6}") |
88 | | - c_python = Cell.from_any([[1, 2, 3], [4, 5, 6]], deepcat=True) |
89 | | - self.assertTrue(c_matlab.tolist() == c_python.tolist()) |
90 | | - |
91 | | - def test_nested_cell_from_matlab(self): |
92 | | - c_matlab = Runtime.call("eval", "{{1, 2, 3}, {4, 5, 6}}") |
93 | | - c_python = Cell.from_any([[1, 2, 3], [4, 5, 6]]) |
94 | | - c_matlab = [x.tolist() for x in c_matlab.tolist()] |
95 | | - c_python = [x.tolist() for x in c_python.tolist()] |
96 | | - self.assertListEqual(c_matlab, c_python) |
| 134 | + def test_instantiate_1d_row_cell_from_matlab(self): |
| 135 | + # Construct a 1x3 cell array in Matlab |
| 136 | + try: |
| 137 | + c_matlab = Runtime.call("eval", "{1, 2, 3}") |
| 138 | + except Exception: |
| 139 | + self.fail('1D row cell from Matlab failed.') |
| 140 | + |
| 141 | + # Check Runtime conversion |
| 142 | + self.assertIsInstance(c_matlab, Cell) |
| 143 | + self.assertTupleEqual(c_matlab.shape, (1, 3)) |
| 144 | + self.assertListEqual(c_matlab.tolist(), [[1, 2, 3]]) |
| 145 | + |
| 146 | + def test_instantiate_1d_col_cell_from_matlab(self): |
| 147 | + # Construct a 3x1 cell array in Matlab |
| 148 | + try: |
| 149 | + c_matlab = Runtime.call("eval", "{1; 2; 3}") |
| 150 | + except Exception: |
| 151 | + self.fail('1D col cell from Matlab failed.') |
| 152 | + |
| 153 | + # Check Runtime conversion |
| 154 | + self.assertIsInstance(c_matlab, Cell) |
| 155 | + self.assertTupleEqual(c_matlab.shape, (3, 1)) |
| 156 | + self.assertListEqual(c_matlab.tolist(), [[1], [2], [3]]) |
| 157 | + |
| 158 | + def test_instantiate_2d_cell_from_matlab(self): |
| 159 | + # Construct a 2x3 cell array in Matlab |
| 160 | + try: |
| 161 | + c_matlab = Runtime.call("eval", "{1, 2, 3; 4, 5, 6}") |
| 162 | + except Exception: |
| 163 | + self.fail('2D cell from Matlab failed.') |
| 164 | + |
| 165 | + # Check Runtime conversion |
| 166 | + self.assertIsInstance(c_matlab, Cell) |
| 167 | + self.assertTupleEqual(c_matlab.shape, (2, 3)) |
| 168 | + self.assertListEqual(c_matlab.tolist(), [[1, 2, 3], [4, 5, 6]]) |
| 169 | + |
| 170 | + def test_instantiate_nested_cell_from_matlab(self): |
| 171 | + # Construct a nested cell array |
| 172 | + try: |
| 173 | + c_matlab = Runtime.call("eval", "{{1, 2, 3}, {4, 5, 6}}") |
| 174 | + except Exception: |
| 175 | + self.fail('Nested cell from Matlab failed.') |
| 176 | + |
| 177 | + # Check Runtime conversion |
| 178 | + self.assertIsInstance(c_matlab, Cell) |
| 179 | + self.assertTupleEqual(c_matlab.shape, (2,)) |
| 180 | + self.assertTrue(all(isinstance(x, Cell) for x in c_matlab)) |
| 181 | + self.assertTrue(all(len(x.shape) == 1 for x in c_matlab)) |
| 182 | + self.assertListEqual(c_matlab[0].tolist(), [[1, 2, 3]]) |
| 183 | + self.assertListEqual(c_matlab[1].tolist(), [[4, 5, 6]]) |
| 184 | + |
| 185 | + def test_instantiate_empty_cell_from_matlab(self): |
| 186 | + # Construct an empty cell array in Matlab |
| 187 | + try: |
| 188 | + c_matlab = Runtime.call("eval", "{}") |
| 189 | + except Exception: |
| 190 | + self.fail('Empty cell from Matlab failed.') |
| 191 | + |
| 192 | + # Check Runtime conversion |
| 193 | + self.assertIsInstance(c_matlab, Cell) |
| 194 | + self.assertTupleEqual(c_matlab.shape, (0,)) |
| 195 | + |
| 196 | + def test_instantiate_empty_1d_row_cell_from_matlab(self): |
| 197 | + # Construct a 1x3 cell array in Matlab |
| 198 | + try: |
| 199 | + c_matlab = Runtime.call('cell', 3, 1) |
| 200 | + except Exception: |
| 201 | + self.fail('1D empty row cell from Matlab failed.') |
| 202 | + |
| 203 | + # Check Runtime conversion |
| 204 | + self.assertIsInstance(c_matlab, Cell) |
| 205 | + self.assertTupleEqual(c_matlab.shape, (3, 1)) |
| 206 | + self.assertTrue(all(isinstance(x, Array) for x in c_matlab)) |
| 207 | + self.assertTrue(all(len(x.shape) == 0 for x in c_matlab)) |
| 208 | + |
| 209 | + def test_instantiate_empty_1d_col_cell_from_matlab(self): |
| 210 | + # Construct a 1x3 cell array in Matlab |
| 211 | + try: |
| 212 | + c_matlab = Runtime.call('cell', 1, 3) |
| 213 | + except Exception: |
| 214 | + self.fail('1D empty col cell from Matlab failed.') |
| 215 | + |
| 216 | + # Check Runtime conversion |
| 217 | + self.assertIsInstance(c_matlab, Cell) |
| 218 | + self.assertTupleEqual(c_matlab.shape, (1, 3)) |
| 219 | + self.assertTrue(all(isinstance(x, Array) for x in c_matlab.flat)) |
| 220 | + self.assertTrue(all(len(x.shape) == 0 for x in c_matlab.flat)) |
| 221 | + |
| 222 | + def test_instantiate_empty_2d_cell_from_matlab(self): |
| 223 | + # Construct a 3x2 cell array in Matlab |
| 224 | + try: |
| 225 | + c_matlab = Runtime.call('cell', 3, 2) |
| 226 | + except Exception: |
| 227 | + self.fail('2D empty cell from Matlab failed.') |
| 228 | + |
| 229 | + # Check Runtime conversion |
| 230 | + self.assertIsInstance(c_matlab, Cell) |
| 231 | + self.assertTupleEqual(c_matlab.shape, (3, 2)) |
| 232 | + self.assertTrue(all(isinstance(x, Array) for x in c_matlab.flat)) |
| 233 | + self.assertTrue(all(len(x.shape) == 0 for x in c_matlab.flat)) |
97 | 234 |
|
98 | 235 | def test_append_1d(self): |
99 | 236 | c = Cell.from_any([1, 2, 3], owndata=True) |
|
0 commit comments