|
21 | 21 | FIX_2D_SILO = os.path.join(FIXTURES, '2d_silo') |
22 | 22 | FIX_3D_BIN = os.path.join(FIXTURES, '3d_binary') |
23 | 23 | FIX_3D_SILO = os.path.join(FIXTURES, '3d_silo') |
| 24 | +FIX_1D_BIN_2RANK = os.path.join(FIXTURES, '1d_binary_2rank') |
24 | 25 |
|
25 | 26 |
|
26 | 27 | # --------------------------------------------------------------------------- |
@@ -104,6 +105,14 @@ def test_ellipsis_must_be_second_to_last(self): |
104 | 105 | with self.assertRaises(MFCException): |
105 | 106 | self._parse('0,100,...,500,1000', [0, 100, 500, 1000]) |
106 | 107 |
|
| 108 | + def test_ellipsis_n_requested_is_expanded_range(self): |
| 109 | + """Ellipsis n_requested reflects the expanded range, not the matched count.""" |
| 110 | + from .viz import _parse_steps |
| 111 | + # Range 0,100,...,1000 expands to 11 steps; only 3 are available. |
| 112 | + matched, n_req = _parse_steps('0,100,...,1000', [0, 200, 1000]) |
| 113 | + self.assertEqual(n_req, 11) |
| 114 | + self.assertEqual(matched, [0, 200, 1000]) |
| 115 | + |
107 | 116 | def test_invalid_value(self): |
108 | 117 | """Non-numeric, non-keyword input raises MFCException.""" |
109 | 118 | from mfc.common import MFCException |
@@ -230,6 +239,44 @@ def test_var_filter(self): |
230 | 239 | self.assertNotIn('vel1', data.variables) |
231 | 240 |
|
232 | 241 |
|
| 242 | +class TestAssembleBinary1DMultiRank(unittest.TestCase): |
| 243 | + """Test multi-rank assembly with overlapping ghost cells (1D, 2 ranks).""" |
| 244 | + |
| 245 | + def test_ndim(self): |
| 246 | + """2-rank 1D fixture assembles with ndim=1.""" |
| 247 | + from .reader import assemble |
| 248 | + data = assemble(FIX_1D_BIN_2RANK, 0, 'binary') |
| 249 | + self.assertEqual(data.ndim, 1) |
| 250 | + |
| 251 | + def test_cell_count_after_dedup(self): |
| 252 | + """Ghost cell overlap is deduplicated: 16 unique cells from two overlapping ranks.""" |
| 253 | + from .reader import assemble |
| 254 | + data = assemble(FIX_1D_BIN_2RANK, 0, 'binary') |
| 255 | + self.assertEqual(len(data.x_cc), 16) |
| 256 | + |
| 257 | + def test_grid_is_sorted_and_unique(self): |
| 258 | + """Assembled global grid is strictly increasing with no duplicates.""" |
| 259 | + import numpy as np |
| 260 | + from .reader import assemble |
| 261 | + data = assemble(FIX_1D_BIN_2RANK, 0, 'binary') |
| 262 | + diffs = np.diff(data.x_cc) |
| 263 | + self.assertTrue(bool(np.all(diffs > 0)), "x_cc is not strictly increasing") |
| 264 | + |
| 265 | + def test_variable_values_match_position(self): |
| 266 | + """pres values (== x_cc position) are placed at the correct global cells.""" |
| 267 | + import numpy as np |
| 268 | + from .reader import assemble |
| 269 | + data = assemble(FIX_1D_BIN_2RANK, 0, 'binary') |
| 270 | + np.testing.assert_allclose(data.variables['pres'], data.x_cc, atol=1e-10) |
| 271 | + |
| 272 | + def test_all_vars_present(self): |
| 273 | + """Both variables written by both ranks appear in the assembled output.""" |
| 274 | + from .reader import assemble |
| 275 | + data = assemble(FIX_1D_BIN_2RANK, 0, 'binary') |
| 276 | + self.assertIn('pres', data.variables) |
| 277 | + self.assertIn('rho', data.variables) |
| 278 | + |
| 279 | + |
233 | 280 | class TestAssembleBinary2D(unittest.TestCase): |
234 | 281 | """Test binary reader with 2D fixture data.""" |
235 | 282 |
|
|
0 commit comments