Skip to content

Commit

Permalink
[TEST] use EXPECT_RANGE_EQ in persist_test.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
marehr committed Mar 17, 2021
1 parent 1bd75fd commit ec95459
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions test/unit/range/views/persist_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,74 @@

#include <seqan3/std/concepts>
#include <seqan3/std/ranges>
#include <string>

#include <range/v3/algorithm/copy.hpp>
#include <range/v3/view/unique.hpp>

#include <seqan3/range/views/persist.hpp>
#include <seqan3/range/views/to.hpp>
#include <seqan3/range/concept.hpp>
#include <seqan3/utility/char_operations/predicate.hpp>
#include <seqan3/test/expect_range_eq.hpp>

// ============================================================================
// test templates
// ============================================================================

TEST(view_persist, delegate_to_view_all)
{
using namespace std::literals;

std::string vec{"foo"};

// pipe notation
auto v = vec | seqan3::views::persist;
EXPECT_EQ("foo", v | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("foo"sv, v);

// function notation
std::string v2 = seqan3::views::persist(vec) | seqan3::views::to<std::string>;
EXPECT_EQ("foo", v2);
EXPECT_RANGE_EQ("foo"sv, seqan3::views::persist(vec));

// combinability
auto v3 = vec | seqan3::views::persist | ranges::views::unique;
EXPECT_EQ("fo", v3 | seqan3::views::to<std::string>);
std::string v3b = vec
| std::views::reverse
| seqan3::views::persist
| ranges::views::unique
| seqan3::views::to<std::string>;
EXPECT_EQ("of", v3b);
EXPECT_RANGE_EQ("fo"sv, vec | seqan3::views::persist | ranges::views::unique);
EXPECT_RANGE_EQ("of"sv, vec | std::views::reverse | seqan3::views::persist | ranges::views::unique);

// store combined
auto a1 = seqan3::views::persist | ranges::views::unique;
auto v5 = vec | a1;
EXPECT_EQ("fo", v5 | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("fo"sv, vec | a1);
}

TEST(view_persist, wrap_temporary)
{
using namespace std::literals;

// pipe notation
auto v = std::string{"foo"} | seqan3::views::persist;
EXPECT_EQ("foo", v | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("foo"sv, std::string{"foo"} | seqan3::views::persist);

// function notation
std::string v2 = seqan3::views::persist(std::string{"foo"}) | seqan3::views::to<std::string>;
EXPECT_EQ("foo", v2);
EXPECT_RANGE_EQ("foo"sv, seqan3::views::persist(std::string{"foo"}));

// combinability
auto v3 = std::string{"foo"} | seqan3::views::persist | ranges::views::unique;
EXPECT_EQ("fo", v3 | seqan3::views::to<std::string>);
std::string v3b = std::string{"foo"}
| seqan3::views::persist
| std::views::filter(seqan3::is_char<'o'>)
| ranges::views::unique
| seqan3::views::to<std::string>;
EXPECT_EQ("o", v3b);
EXPECT_RANGE_EQ("fo"sv, std::string{"foo"} | seqan3::views::persist | ranges::views::unique);
EXPECT_RANGE_EQ("o"sv, std::string{"foo"} | seqan3::views::persist
| std::views::filter([](char const chr){return chr == 'o';})
| ranges::views::unique);
}

TEST(view_persist, const)
{
using namespace std::literals;

// inner const
using t = std::string const;
auto v = t{"foo"} | seqan3::views::persist;
EXPECT_EQ("foo", v | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("foo"sv, t{"foo"} | seqan3::views::persist);

// outer const
auto const & v2 = std::string{"foo"} | seqan3::views::persist;
EXPECT_EQ("foo", v2 | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("foo"sv, v2);

// inner + outer const
using t = std::string const;
auto const & v3 = t{"foo"} | seqan3::views::persist;
EXPECT_EQ("foo", v3 | seqan3::views::to<std::string>);
EXPECT_RANGE_EQ("foo"sv, v3);
}

TEST(view_persist, concepts)
Expand Down

0 comments on commit ec95459

Please sign in to comment.