-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathsort_array.cpp
63 lines (54 loc) · 1.91 KB
/
sort_array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2018-2022 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <functional>
#include <catch2/catch_test_macros.hpp>
#include <cpp-sort/sort.h>
#include <cpp-sort/sorters/selection_sorter.h>
#include <cpp-sort/utility/functional.h>
#include <testing-tools/algorithm.h>
TEST_CASE( "test sorting C arrays", "[sort]" )
{
int arr[] = { 8, 1, 6, 7, 3, 5, 4, 9, 2 };
SECTION( "without anything" )
{
cppsort::sort(arr);
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr)) );
}
SECTION( "with comparison function" )
{
cppsort::sort(arr, std::greater<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr), std::greater<>{}) );
}
SECTION( "with projection function" )
{
cppsort::sort(arr, std::negate<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr), std::greater<>{}) );
}
SECTION( "with comparison and projection functions" )
{
cppsort::sort(arr, std::greater<>{}, std::negate<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr)) );
}
SECTION( "with sorter" )
{
cppsort::sort(cppsort::selection_sort, arr);
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr)) );
}
SECTION( "with sorter and comparison function" )
{
cppsort::sort(cppsort::selection_sort, arr, std::greater<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr), std::greater<>{}) );
}
SECTION( "with sorter and projection function" )
{
cppsort::sort(cppsort::selection_sort, arr, std::negate<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr), std::greater<>{}) );
}
SECTION( "with sorter, comparison and projection function" )
{
cppsort::sort(cppsort::selection_sort, arr, std::greater<>{}, std::negate<>{});
CHECK( helpers::is_sorted(std::begin(arr), std::end(arr)) );
}
}