Skip to content

Commit a168d00

Browse files
committed
Test that Dis(XY) = max{Dis(X), Dis(Y)} when X <= Y
1 parent 95dbc65 commit a168d00

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/probes/dis.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
* Copyright (c) 2016-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5+
#include <algorithm>
56
#include <forward_list>
7+
#include <random>
8+
#include <type_traits>
69
#include <vector>
710
#include <catch2/catch_test_macros.hpp>
11+
#include <rapidcheck.h>
12+
#include <rapidcheck/catch.h>
813
#include <cpp-sort/probes/dis.h>
914
#include <cpp-sort/utility/size.h>
1015
#include <testing-tools/internal_compare.h>
16+
#include <testing-tools/random.h>
1117

1218
TEST_CASE( "measure of disorder: dis", "[probe][dis]" )
1319
{
@@ -58,4 +64,22 @@ TEST_CASE( "measure of disorder: dis", "[probe][dis]" )
5864
CHECK( dis(li) == max_n );
5965
CHECK( dis(li.begin(), li.end()) == max_n );
6066
}
67+
68+
// Sorting and Measures of Disorder
69+
// by Vladimir Estivill-Castro
70+
71+
rc::prop("Dis(XY) = max{Dis(X), Dis(Y)} if X ≤ Y", [](std::vector<int> sequence) {
72+
using diff_t = std::vector<int>::difference_type;
73+
using param_t = std::uniform_int_distribution<diff_t>::param_type;
74+
75+
// Split the sequence into two consecutive subsequences X and Y
76+
auto size = static_cast<diff_t>(sequence.size());
77+
std::uniform_int_distribution<diff_t> dist;
78+
auto x_begin = sequence.begin();
79+
auto y_begin = x_begin + dist(hasard::engine(), param_t{0, size});
80+
std::nth_element(x_begin, y_begin, sequence.end());
81+
82+
using cppsort::probe::dis;
83+
return dis(sequence) == (std::max)(dis(x_begin, y_begin), dis(y_begin, sequence.end()));
84+
});
6185
}

0 commit comments

Comments
 (0)