Skip to content

Commit

Permalink
Reduce usage of cppsort::sort in the test suite (issue #167)
Browse files Browse the repository at this point in the history
cppsort::sort and cppsort::stable_sort are deprecated and will be
removed in version 2.0.0. This commit drastically reduces their use in
the test suite and only keep them where they are specifically tested
because they're relevant.

This should also reduce the parsing time of the test suite: since the
header drags default_sorter along the way it tends to be heavy for tests
where a single sorter is needed.

This commit also fixes a few minor style issues or include issues that
were hidden by transitive includes along the way.
  • Loading branch information
Morwenn committed Jul 18, 2020
1 parent b59708c commit d84990f
Show file tree
Hide file tree
Showing 51 changed files with 444 additions and 612 deletions.
29 changes: 13 additions & 16 deletions testsuite/adapters/container_aware_adapter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2018 Morwenn
* Copyright (c) 2016-2020 Morwenn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,7 +26,6 @@
#include <type_traits>
#include <catch2/catch.hpp>
#include <cpp-sort/adapters/container_aware_adapter.h>
#include <cpp-sort/sort.h>
#include <cpp-sort/sorters/merge_sorter.h>
#include "../algorithm.h"

Expand Down Expand Up @@ -56,39 +55,37 @@ namespace foobar
TEST_CASE( "basic tests with container_aware_adapter",
"[container_aware_adapter]" )
{
using sorter = cppsort::container_aware_adapter<
using sorter_t = cppsort::container_aware_adapter<
cppsort::merge_sorter
>;
sorter_t sorter;

// Cool list to "sort"
foobar::cool_list<int> collection;

SECTION( "with comparison" )
{
CHECK( sorter{}(collection, std::greater<>{}) );
CHECK( cppsort::sort(sorter{}, collection, std::greater<>{}) );
CHECK( not cppsort::is_stable<sorter(foobar::cool_list<int>&, std::greater<>)>::value );
CHECK( sorter(collection, std::greater<>{}) );
CHECK( not cppsort::is_stable<sorter_t(foobar::cool_list<int>&, std::greater<>)>::value );
}

SECTION( "with projection" )
{
CHECK( sorter{}(collection, std::negate<>{}) );
CHECK( cppsort::sort(sorter{}, collection, std::negate<>{}) );
CHECK( not cppsort::is_stable<sorter(foobar::cool_list<int>&, std::negate<>)>::value );
CHECK( sorter(collection, std::negate<>{}) );
CHECK( not cppsort::is_stable<sorter_t(foobar::cool_list<int>&, std::negate<>)>::value );
}

SECTION( "with automagic comparison-projection" )
{
CHECK( sorter{}(collection, std::greater<>{}, std::negate<>{}) );
CHECK( cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{}) );
CHECK( not cppsort::is_stable<sorter(foobar::cool_list<int>&, std::greater<>, std::negate<>)>::value );
CHECK( sorter(collection, std::greater<>{}, std::negate<>{}) );
CHECK( not cppsort::is_stable<sorter_t(foobar::cool_list<int>&, std::greater<>, std::negate<>)>::value );
}

SECTION( "more about stability" )
{
CHECK( cppsort::is_stable<sorter(std::list<int>&)>::value );
CHECK( cppsort::is_stable<sorter(std::list<int>::iterator, std::list<int>::iterator)>::value );
CHECK( cppsort::is_stable<sorter(foobar::cool_list<int>::iterator,
foobar::cool_list<int>::iterator)>::value );
CHECK( cppsort::is_stable<sorter_t(std::list<int>&)>::value );
CHECK( cppsort::is_stable<sorter_t(std::list<int>::iterator, std::list<int>::iterator)>::value );
CHECK( cppsort::is_stable<sorter_t(foobar::cool_list<int>::iterator,
foobar::cool_list<int>::iterator)>::value );
}
}
75 changes: 19 additions & 56 deletions testsuite/adapters/container_aware_adapter_forward_list.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2018 Morwenn
* Copyright (c) 2016-2020 Morwenn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -28,7 +28,6 @@
#include <vector>
#include <catch2/catch.hpp>
#include <cpp-sort/adapters/container_aware_adapter.h>
#include <cpp-sort/sort.h>
#include <cpp-sort/sorters/insertion_sorter.h>
#include <cpp-sort/sorters/merge_sorter.h>
#include <cpp-sort/sorters/selection_sorter.h>
Expand All @@ -46,115 +45,79 @@ TEST_CASE( "container_aware_adapter and std::forward_list",

SECTION( "insertion_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::insertion_sorter
>;
> sorter;
std::forward_list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}

SECTION( "merge_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::merge_sorter
>;
> sorter;
std::forward_list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}

SECTION( "selection_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::selection_sorter
>;
> sorter;
std::forward_list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}
}
75 changes: 19 additions & 56 deletions testsuite/adapters/container_aware_adapter_list.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2018 Morwenn
* Copyright (c) 2016-2020 Morwenn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -28,7 +28,6 @@
#include <vector>
#include <catch2/catch.hpp>
#include <cpp-sort/adapters/container_aware_adapter.h>
#include <cpp-sort/sort.h>
#include <cpp-sort/sorters/insertion_sorter.h>
#include <cpp-sort/sorters/merge_sorter.h>
#include <cpp-sort/sorters/selection_sorter.h>
Expand All @@ -46,115 +45,79 @@ TEST_CASE( "container_aware_adapter and std::list",

SECTION( "insertion_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::insertion_sorter
>;
> sorter;
std::list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}

SECTION( "merge_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::merge_sorter
>;
> sorter;
std::list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}

SECTION( "selection_sorter" )
{
using sorter = cppsort::container_aware_adapter<
cppsort::container_aware_adapter<
cppsort::selection_sorter
>;
> sorter;
std::list<double> collection(std::begin(vec), std::end(vec));

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{});
sorter(collection, std::greater<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::negate<>{});
sorter(collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection), std::greater<>{}) );

collection = { std::begin(vec), std::end(vec) };
sorter{}(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

collection = { std::begin(vec), std::end(vec) };
cppsort::sort(sorter{}, collection, std::greater<>{}, std::negate<>{});
sorter(collection, std::greater<>{}, std::negate<>{});
CHECK( std::is_sorted(std::begin(collection), std::end(collection)) );

// Make sure that the generic overload is also called when needed

auto vec_copy = vec;
cppsort::sort(sorter{}, vec_copy);
sorter(vec_copy);
CHECK( std::is_sorted(std::begin(vec_copy), std::end(vec_copy)) );
}
}
Loading

0 comments on commit d84990f

Please sign in to comment.