Skip to content

Commit

Permalink
Move filter unit tests to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
davidstone committed Nov 29, 2023
1 parent b2a7f8b commit 52322dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ target_sources(containers_test PRIVATE
test/containers/sort/test_sort.cpp
test/containers/algorithms/copy_or_relocate_from.cpp
test/containers/algorithms/erase.cpp
test/containers/algorithms/filter.cpp
test/containers/algorithms/split.cpp
test/containers/algorithms/zip.cpp
test/containers/append.cpp
Expand Down
12 changes: 1 addition & 11 deletions source/containers/algorithms/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ module;
export module containers.algorithms.filter;

import containers.algorithms.advance;
import containers.algorithms.compare;
import containers.algorithms.find;

import containers.adapt_iterator;
import containers.array;
import containers.begin_end;
import containers.default_adapt_traits;
import containers.default_begin_end_size;
Expand Down Expand Up @@ -132,12 +131,3 @@ template<typename Range, typename UnaryPredicate>
filter(Range &&, UnaryPredicate) -> filter<Range, UnaryPredicate>;

} // namespace containers

constexpr auto check_filter() {
constexpr auto source = containers::array{1_bi, 2_bi, 3_bi, 2_bi, 4_bi, 5_bi, 6_bi, 8_bi};
constexpr auto expected = containers::array{2_bi, 2_bi, 4_bi, 6_bi, 8_bi};
auto const filtered = containers::filter(source, [](auto const integer) { return integer % 2_bi == 0_bi; });
return containers::equal(filtered, expected);
}

static_assert(check_filter());
31 changes: 31 additions & 0 deletions test/containers/algorithms/filter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright David Stone 2023.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

export module containers.test.algorithms.filter;

import containers.algorithms.compare;
import containers.algorithms.filter;

import containers.array;

import bounded;

using namespace bounded::literal;

// https://github.com/llvm/llvm-project/issues/59513
struct is_even {
static constexpr auto operator()(auto const integer) {
return integer % 2_bi == 0_bi;
}
};

constexpr auto check_filter() {
constexpr auto source = containers::array{1_bi, 2_bi, 3_bi, 2_bi, 4_bi, 5_bi, 6_bi, 8_bi};
constexpr auto expected = containers::array{2_bi, 2_bi, 4_bi, 6_bi, 8_bi};
auto const filtered = containers::filter(source, is_even());
return containers::equal(filtered, expected);
}

static_assert(check_filter());

0 comments on commit 52322dc

Please sign in to comment.