Skip to content

Commit e9e1977

Browse files
committed
Make distribution tests more robust
1 parent 4e7321d commit e9e1977

13 files changed

+115
-156
lines changed

tests/distributions/all_equal.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test random-access sorters with all_equal distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test random-access sorters with all_equal distribution", "[
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::all_equal{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::all_equal{});
5346
}

tests/distributions/alternating.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with alternating distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test sorter with alternating distribution", "[distributions
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::alternating{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::alternating{});
5346
}

tests/distributions/ascending.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with ascending distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -48,11 +47,5 @@ TEMPLATE_TEST_CASE( "test sorter with ascending distribution", "[distributions]"
4847
> )
4948
{
5049
std::vector<int> collection;
51-
collection.reserve(10'000);
52-
auto distribution = dist::ascending{};
53-
distribution(std::back_inserter(collection), 10'000);
54-
55-
TestType sorter;
56-
sorter(collection);
57-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
50+
helpers::test_distribution<TestType>(collection, 10'000, dist::ascending{});
5851
}

tests/distributions/ascending_sawtooth.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <list>
86
#include <vector>
97
#include <catch2/catch_template_test_macros.hpp>
108
#include <cpp-sort/sorters.h>
119
#include <cpp-sort/utility/buffer.h>
1210
#include <cpp-sort/utility/functional.h>
1311
#include <testing-tools/distributions.h>
12+
#include "test_distribution.h"
1413

1514
TEMPLATE_TEST_CASE( "test random-access sorters with ascending_sawtooth distribution", "[distributions]",
1615
cppsort::adaptive_shivers_sorter,
@@ -44,13 +43,7 @@ TEMPLATE_TEST_CASE( "test random-access sorters with ascending_sawtooth distribu
4443
> )
4544
{
4645
std::vector<int> collection;
47-
collection.reserve(10'000);
48-
auto distribution = dist::ascending_sawtooth{};
49-
distribution(std::back_inserter(collection), 10'000);
50-
51-
TestType sorter;
52-
sorter(collection);
53-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
46+
helpers::test_distribution<TestType>(collection, 10'000, dist::ascending_sawtooth{});
5447
}
5548

5649
TEMPLATE_TEST_CASE( "test bidirectional sorters with ascending_sawtooth distribution", "[distributions]",
@@ -64,10 +57,5 @@ TEMPLATE_TEST_CASE( "test bidirectional sorters with ascending_sawtooth distribu
6457
cppsort::verge_sorter )
6558
{
6659
std::list<int> collection;
67-
auto distribution = dist::ascending_sawtooth{};
68-
distribution(std::back_inserter(collection), 1000);
69-
70-
TestType sorter;
71-
sorter(collection);
72-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
60+
helpers::test_distribution<TestType>(collection, 1000, dist::ascending_sawtooth{});
7361
}

tests/distributions/descending.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with descending distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test sorter with descending distribution", "[distributions]
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::descending{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::descending{});
5346
}

tests/distributions/descending_sawtooth.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <list>
86
#include <vector>
97
#include <catch2/catch_template_test_macros.hpp>
108
#include <cpp-sort/sorters.h>
119
#include <cpp-sort/utility/buffer.h>
1210
#include <cpp-sort/utility/functional.h>
1311
#include <testing-tools/distributions.h>
12+
#include "test_distribution.h"
1413

1514
TEMPLATE_TEST_CASE( "test random-access sorters with descending_sawtooth distribution", "[distributions]",
1615
cppsort::adaptive_shivers_sorter,
@@ -44,13 +43,7 @@ TEMPLATE_TEST_CASE( "test random-access sorters with descending_sawtooth distrib
4443
> )
4544
{
4645
std::vector<int> collection;
47-
collection.reserve(10'000);
48-
auto distribution = dist::descending_sawtooth{};
49-
distribution(std::back_inserter(collection), 10'000);
50-
51-
TestType sorter;
52-
sorter(collection);
53-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
46+
helpers::test_distribution<TestType>(collection, 10'000, dist::descending_sawtooth{});
5447
}
5548

5649
TEMPLATE_TEST_CASE( "test bidirectional sorters with descending_sawtooth distribution", "[distributions]",
@@ -64,10 +57,5 @@ TEMPLATE_TEST_CASE( "test bidirectional sorters with descending_sawtooth distrib
6457
cppsort::verge_sorter )
6558
{
6659
std::list<int> collection;
67-
auto distribution = dist::descending_sawtooth{};
68-
distribution(std::back_inserter(collection), 1000);
69-
70-
TestType sorter;
71-
sorter(collection);
72-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
60+
helpers::test_distribution<TestType>(collection, 1000, dist::descending_sawtooth{});
7361
}

tests/distributions/median_of_3_killer.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
2-
* Copyright (c) 2020-2023 Morwenn
2+
* Copyright (c) 2020-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <list>
86
#include <vector>
97
#include <catch2/catch_template_test_macros.hpp>
108
#include <cpp-sort/sorters.h>
119
#include <cpp-sort/utility/buffer.h>
1210
#include <cpp-sort/utility/functional.h>
1311
#include <testing-tools/distributions.h>
12+
#include "test_distribution.h"
1413

1514
TEMPLATE_TEST_CASE( "test random-access sorters with median_of_3_killer distribution", "[distributions]",
1615
cppsort::adaptive_shivers_sorter,
@@ -44,13 +43,7 @@ TEMPLATE_TEST_CASE( "test random-access sorters with median_of_3_killer distribu
4443
> )
4544
{
4645
std::vector<int> collection;
47-
collection.reserve(1000);
48-
auto distribution = dist::median_of_3_killer{};
49-
distribution(std::back_inserter(collection), 1000);
50-
51-
TestType sorter;
52-
sorter(collection);
53-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
46+
helpers::test_distribution<TestType>(collection, 1000, dist::median_of_3_killer{});
5447
}
5548

5649
TEMPLATE_TEST_CASE( "test bidirectional sorters with median_of_3_killer distribution", "[distributions]",
@@ -64,10 +57,5 @@ TEMPLATE_TEST_CASE( "test bidirectional sorters with median_of_3_killer distribu
6457
cppsort::verge_sorter )
6558
{
6659
std::list<int> collection;
67-
auto distribution = dist::median_of_3_killer{};
68-
distribution(std::back_inserter(collection), 1000);
69-
70-
TestType sorter;
71-
sorter(collection);
72-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
60+
helpers::test_distribution<TestType>(collection, 1000, dist::median_of_3_killer{});
7361
}

tests/distributions/pipe_organ.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with pipe_organ distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test sorter with pipe_organ distribution", "[distributions]
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::pipe_organ{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::pipe_organ{});
5346
}

tests/distributions/push_front.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with push_front distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test sorter with push_front distribution", "[distributions]
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::push_front{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::push_front{});
5346
}

tests/distributions/push_middle.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/*
2-
* Copyright (c) 2017-2022 Morwenn
2+
* Copyright (c) 2017-2024 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
5-
#include <algorithm>
6-
#include <iterator>
75
#include <vector>
86
#include <catch2/catch_template_test_macros.hpp>
97
#include <cpp-sort/sorters.h>
108
#include <cpp-sort/utility/buffer.h>
119
#include <cpp-sort/utility/functional.h>
1210
#include <testing-tools/distributions.h>
11+
#include "test_distribution.h"
1312

1413
TEMPLATE_TEST_CASE( "test sorter with push_middle distribution", "[distributions]",
1514
cppsort::adaptive_shivers_sorter,
@@ -43,11 +42,5 @@ TEMPLATE_TEST_CASE( "test sorter with push_middle distribution", "[distributions
4342
> )
4443
{
4544
std::vector<int> collection;
46-
collection.reserve(10'000);
47-
auto distribution = dist::push_middle{};
48-
distribution(std::back_inserter(collection), 10'000);
49-
50-
TestType sorter;
51-
sorter(collection);
52-
CHECK( std::is_sorted(collection.begin(), collection.end()) );
45+
helpers::test_distribution<TestType>(collection, 10'000, dist::push_middle{});
5346
}

0 commit comments

Comments
 (0)