Skip to content

Commit e841ec2

Browse files
committed
Review changes: explain scrambling; in-place scramble doesn't return result
1 parent 62285b5 commit e841ec2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/iris/tests/unit/util/test_equalise_cubes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818

1919

2020
def _scramble(inputs, rng=95297):
21-
# Reorder items to check that order does not affect the operation
21+
# Reorder items (IN PLACE) to check that order does not affect operation
22+
# NOTE: the "magic" number is chosen because it happens to encode a permutation
23+
# which is usefully non-trivial for small numbers
24+
# examples:
25+
# [0, 1] --> [1, 0]
26+
# [0, 1, 2] --> [1, 2, 0]
27+
# [0, 1, 2, 3] --> [1, 2, 3, 0]
28+
# [0, 1, 2, 3, 4] --> [1, 2, 3, 0, 4]
29+
# [0, 1, 2, 3, 4, 5] --> [1, 3, 2, 0, 5, 4]
30+
# [0, 1, 2, 3, 4, 5, 6] --> [1, 5, 3, 2, 0, 6, 4]
2231
if not isinstance(rng, Generator):
2332
rng = np.random.default_rng(rng)
2433
n_inputs = len(inputs)
@@ -31,7 +40,6 @@ def _scramble(inputs, rng=95297):
3140
inputs_array = inputs_array[scramble_inds]
3241
# Modify input list **BUT N.B. IN PLACE**
3342
inputs[:] = inputs_array
34-
return inputs
3543

3644

3745
@pytest.fixture(params=["off", "on", "applyall", "scrambled"])
@@ -147,7 +155,7 @@ def test_multi(self, usage):
147155
for stdname, longname, varname in zip(stdnames, longnames, varnames)
148156
]
149157
if usage == "scrambled":
150-
expected_metadatas = _scramble(expected_metadatas)
158+
_scramble(expected_metadatas)
151159

152160
# Apply operation
153161
results = equalise_cubes(test_cubes, **kwargs)

0 commit comments

Comments
 (0)