Skip to content

Commit 71deba7

Browse files
committed
Test Theorem 3.18-2 from Sorting and Measures of Disorder
1 parent d6457a1 commit 71deba7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/probes/every_probe_common.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,35 @@ TEMPLATE_TEST_CASE( "test M(XY) = M(X) + M(Y) if X <= Y for some probes M", "[pr
265265
});
266266
}
267267

268+
TEMPLATE_TEST_CASE( "test M(2, 1, 4, 3, 6, 5, ...) <= |X| * M(2, 1) / 2 for most probes M", "[probe]",
269+
decltype(cppsort::probe::dis),
270+
decltype(cppsort::probe::enc),
271+
decltype(cppsort::probe::exc),
272+
decltype(cppsort::probe::ham),
273+
decltype(cppsort::probe::inv),
274+
decltype(cppsort::probe::max),
275+
decltype(cppsort::probe::rem),
276+
decltype(cppsort::probe::runs),
277+
decltype(cppsort::probe::spear),
278+
decltype(cppsort::probe::sus) )
279+
{
280+
// From *Sorting and Measures of Disorder* by Estivill-Castro:
281+
// property derived from Mannila's criteria 2 & 4
282+
// The following probes don't satisfy it: Block, Mono, Osc
283+
284+
int size = 1000;
285+
std::vector<int> sequence(size, 0);
286+
std::iota(sequence.begin(), sequence.end(), 0);
287+
for (int i = 0; i < size; i += 2) {
288+
std::swap(sequence[i], sequence[i + 1]);
289+
}
290+
291+
int inversion[2] = {2, 1};
292+
293+
std::decay_t<TestType> measure;
294+
CHECK( measure(sequence) <= size * measure(inversion) / 2 );
295+
}
296+
268297
TEMPLATE_TEST_CASE( "test M(aX) <= |X| + M(X) for most probes M", "[probe]",
269298
decltype(cppsort::probe::block),
270299
decltype(cppsort::probe::dis),

0 commit comments

Comments
 (0)