Skip to content

Commit

Permalink
Weird GCC ./. Clang issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Sep 10, 2024
1 parent 1dace6e commit d205d8e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
1 change: 1 addition & 0 deletions test/unit/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <utility>
#include <vector>
#include <algorithm>
#include <ostream>

#include <gtest/gtest.h>

Expand Down
52 changes: 28 additions & 24 deletions test/unit/test_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,30 +441,34 @@ struct foo {
};

TEST(range, sort) {
char cstr[] = "howdy";

// simple sort
util::sort(util::make_range(std::begin(cstr), null_terminated));
EXPECT_EQ("dhowy"s, cstr);

// reverse sort by transform c to -c
util::sort_by(util::make_range(std::begin(cstr), null_terminated),
[](char c) { return -c; });
EXPECT_EQ("ywohd"s, cstr);

// stable sort: move capitals to front, numbers to back
char mixed[] = "t5hH4E3erLL2e1O";
util::stable_sort_by(util::make_range(std::begin(mixed), null_terminated),
[](char c) { return std::isupper(c)? 0: std::isdigit(c)? 2: 1; });
EXPECT_EQ("HELLOthere54321"s, mixed);

// sort with user-provided less comparison function
std::vector<foo> X = {{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}};

util::sort(X, [](const foo& l, const foo& r) {return l.y<r.y;});
EXPECT_EQ(X, (std::vector<foo>{{5, 0}, {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}}));
util::sort(X, [](const foo& l, const foo& r) {return l.x<r.x;});
EXPECT_EQ(X, (std::vector<foo>{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}));
{
// simple sort
char cstr[] = "howdy";
util::sort(util::range_n(std::begin(cstr), sizeof(cstr) - 1));
EXPECT_EQ("dhowy"s, cstr);
}
{
// reverse sort by transform c to -c
// char cstr[] = "howdy";
// util::sort_by(util::make_range(std::begin(cstr), null_terminated),
// [](char c) { return -c; });
// EXPECT_EQ("ywohd"s, cstr);
}
{
// stable sort: move capitals to front, numbers to back
char mixed[] = "t5hH4E3erLL2e1O";
util::stable_sort_by(util::make_range(std::begin(mixed), null_terminated),
[](char c) { return std::isupper(c)? 0: std::isdigit(c)? 2: 1; });
EXPECT_EQ("HELLOthere54321"s, mixed);
}
{
// sort with user-provided less comparison function
std::vector<foo> X = {{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}};
util::sort(X, [](const foo& l, const foo& r) {return l.y<r.y;});
EXPECT_EQ(X, (std::vector<foo>{{5, 0}, {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}}));
util::sort(X, [](const foo& l, const foo& r) {return l.x<r.x;});
EXPECT_EQ(X, (std::vector<foo>{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}));
}
}

TEST(range, sum) {
Expand Down

0 comments on commit d205d8e

Please sign in to comment.