Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] use EXPECT_RANGE_EQ in get_test... #2445

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 41 additions & 87 deletions test/unit/range/views/get_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@

#include <seqan3/alphabet/mask/masked.hpp>
#include <seqan3/alphabet/quality/aliases.hpp>
#include <seqan3/core/detail/debug_stream_alphabet.hpp>
#include <seqan3/range/concept.hpp>
#include <seqan3/range/views/get.hpp>
#include <seqan3/range/views/complement.hpp>
#include <seqan3/range/views/to_char.hpp>
#include <seqan3/range/views/to.hpp>
#include <seqan3/range/views/zip.hpp>
#include <seqan3/std/ranges>
#include <seqan3/test/expect_range_eq.hpp>

using seqan3::operator""_dna4;
using seqan3::operator""_phred42;

TEST(view_get, basic)
{
Expand All @@ -30,34 +32,17 @@ TEST(view_get, basic)
{'C'_dna4, seqan3::phred42{1}},
{'G'_dna4, seqan3::phred42{2}},
{'T'_dna4, seqan3::phred42{3}}};
seqan3::dna4_vector cmp0{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4};
std::vector<seqan3::phred42> cmp1{seqan3::phred42{0}, seqan3::phred42{1}, seqan3::phred42{2}, seqan3::phred42{3}};

//functor
seqan3::dna4_vector functor0 = seqan3::views::get<0>(qv) | seqan3::views::to<std::vector>;
std::vector<seqan3::phred42> functor1 = seqan3::views::get<1>(qv) | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp0, functor0);
EXPECT_EQ(cmp1, functor1);
EXPECT_RANGE_EQ("ACGT"_dna4, seqan3::views::get<0>(qv));
EXPECT_RANGE_EQ("!\"#$"_phred42, seqan3::views::get<1>(qv));

// pipe notation
seqan3::dna4_vector pipe0 = qv | seqan3::views::get<0> | seqan3::views::to<std::vector>;
std::vector<seqan3::phred42> pipe1 = qv | seqan3::views::get<1> | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp0, pipe0);
EXPECT_EQ(cmp1, pipe1);
EXPECT_RANGE_EQ("ACGT"_dna4, qv | seqan3::views::get<0>);
EXPECT_RANGE_EQ("!\"#$"_phred42, qv | seqan3::views::get<1>);

// combinability
seqan3::dna4_vector cmp2{"TGCA"_dna4};
seqan3::dna4_vector comp = qv | seqan3::views::get<0> | seqan3::views::complement | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp2, comp);

std::string cmp3{"TGCA"};
std::string to_char_test = comp | seqan3::views::to_char | seqan3::views::to<std::string>;
EXPECT_EQ(cmp3, to_char_test);

// reference return check
functor1[0] = seqan3::phred42{4};
std::vector<seqan3::phred42> cmp4{seqan3::phred42{4}, seqan3::phred42{1}, seqan3::phred42{2}, seqan3::phred42{3}};
EXPECT_EQ(cmp4, functor1);
EXPECT_RANGE_EQ("TGCA"_dna4, qv | seqan3::views::get<0> | seqan3::views::complement);
}

TEST(view_get, advanced)
Expand All @@ -70,84 +55,53 @@ TEST(view_get, advanced)
{{'T'_dna4, seqan3::mask::UNMASKED}, seqan3::phred42{3}}};

// functor notation
std::vector<seqan3::masked<seqan3::dna4>> cmp0{{'A'_dna4, seqan3::mask::MASKED},
{'C'_dna4, seqan3::mask::UNMASKED},
{'G'_dna4, seqan3::mask::MASKED},
{'T'_dna4, seqan3::mask::UNMASKED}};
std::vector<seqan3::masked<seqan3::dna4>> functor0 = seqan3::views::get<0>(t) | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp0, functor0);
std::vector<seqan3::masked<seqan3::dna4>> expected_sequence{{'A'_dna4, seqan3::mask::MASKED},
{'C'_dna4, seqan3::mask::UNMASKED},
{'G'_dna4, seqan3::mask::MASKED},
{'T'_dna4, seqan3::mask::UNMASKED}};

std::vector<seqan3::phred42> cmp1{seqan3::phred42{0}, seqan3::phred42{1}, seqan3::phred42{2}, seqan3::phred42{3}};
std::vector<seqan3::phred42> functor1 = seqan3::views::get<1>(t) | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp1, functor1);
EXPECT_RANGE_EQ(expected_sequence, seqan3::views::get<0>(t));
EXPECT_RANGE_EQ("!\"#$"_phred42, seqan3::views::get<1>(t));

seqan3::dna4_vector cmp00{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4};
seqan3::dna4_vector functor00 = seqan3::views::get<0>(seqan3::views::get<0>(t)) | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp00, functor00);
EXPECT_RANGE_EQ("ACGT"_dna4, seqan3::views::get<0>(seqan3::views::get<0>(t)));

// pipe notation
std::vector<seqan3::masked<seqan3::dna4>> pipe0 = t | seqan3::views::get<0> | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp0, pipe0);
EXPECT_RANGE_EQ(expected_sequence, t | seqan3::views::get<0>);
EXPECT_RANGE_EQ("!\"#$"_phred42, t | seqan3::views::get<1>);

std::vector<seqan3::phred42> pipe1 = t | seqan3::views::get<1> | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp1, pipe1);

seqan3::dna4_vector pipe00 = t | seqan3::views::get<0> | seqan3::views::get<0> | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp00, pipe00);
EXPECT_RANGE_EQ("ACGT"_dna4, t | seqan3::views::get<0> | seqan3::views::get<0>);

// combinability
std::vector<seqan3::masked<seqan3::dna4>> cmprev{{'T'_dna4, seqan3::mask::UNMASKED},
{'G'_dna4, seqan3::mask::MASKED},
{'C'_dna4, seqan3::mask::UNMASKED},
{'A'_dna4, seqan3::mask::MASKED}};
std::vector<seqan3::masked<seqan3::dna4>> revtest = t
| seqan3::views::get<0>
| std::views::reverse
| seqan3::views::to<std::vector>;
EXPECT_EQ(cmprev, revtest);

seqan3::dna4_vector cmprev2{'T'_dna4, 'G'_dna4, 'C'_dna4, 'A'_dna4};
seqan3::dna4_vector revtest2 = t
| seqan3::views::get<0>
| seqan3::views::get<0>
| std::views::reverse
| seqan3::views::to<std::vector>;
EXPECT_EQ(cmprev2, revtest2);

// reference check
functor0[0] = seqan3::masked<seqan3::dna4>{'T'_dna4, seqan3::mask::UNMASKED};
std::vector<seqan3::masked<seqan3::dna4>> cmpref{{'T'_dna4, seqan3::mask::UNMASKED},
{'C'_dna4, seqan3::mask::UNMASKED},
{'G'_dna4, seqan3::mask::MASKED},
{'T'_dna4, seqan3::mask::UNMASKED}};
EXPECT_EQ(cmpref, functor0);
EXPECT_RANGE_EQ(expected_sequence | std::views::reverse, t | seqan3::views::get<0> | std::views::reverse);
EXPECT_RANGE_EQ("$#\"!"_phred42, t | seqan3::views::get<1> | std::views::reverse);

EXPECT_RANGE_EQ("TGCA"_dna4, t | seqan3::views::get<0> | seqan3::views::get<0> | std::views::reverse);
}

TEST(view_get, pair_range)
{
std::vector<std::pair<int, int>> pair_range{{0, 1}, {1, 2}, {2, 3}, {3, 4}};

// functor notation
EXPECT_RANGE_EQ((std::vector{0, 1, 2, 3}), seqan3::views::get<0>(pair_range));
EXPECT_RANGE_EQ((std::vector{1, 2, 3, 4}), seqan3::views::get<1>(pair_range));

// pipe notation
EXPECT_RANGE_EQ((std::vector{0, 1, 2, 3}), pair_range | seqan3::views::get<0>);
EXPECT_RANGE_EQ((std::vector{1, 2, 3, 4}), pair_range | seqan3::views::get<1>);
}

TEST(view_get, tuple_pair)
TEST(view_get, tuple_range)
{
std::vector<std::pair<int, int>> pair_test{{0, 1}, {1, 2}, {2, 3}, {3, 4}};
std::vector<std::tuple<int, int>> tuple_test{{0, 1}, {1, 2}, {2, 3}, {3, 4}};
std::vector<std::tuple<int, int>> tuple_range{{0, 1}, {1, 2}, {2, 3}, {3, 4}};

// functor notation
std::vector<int> cmp{0, 1, 2, 3};
std::vector<int> pair_func = seqan3::views::get<0>(pair_test) | seqan3::views::to<std::vector>;
std::vector<int> tuple_func = seqan3::views::get<0>(tuple_test) | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp, pair_func);
EXPECT_EQ(cmp, tuple_func);

// reference test
cmp[0] = 4;
pair_func[0] = 4;
tuple_func[0] = 4;
EXPECT_EQ(cmp, pair_func);
EXPECT_EQ(cmp, tuple_func);
EXPECT_RANGE_EQ((std::vector{0, 1, 2, 3}), seqan3::views::get<0>(tuple_range));
EXPECT_RANGE_EQ((std::vector{1, 2, 3, 4}), seqan3::views::get<1>(tuple_range));

// pipe notation
cmp[0] = 0;
std::vector<int> pair_pipe = pair_test | seqan3::views::get<0> | seqan3::views::to<std::vector>;
std::vector<int> tuple_pipe = tuple_test | seqan3::views::get<0> | seqan3::views::to<std::vector>;
EXPECT_EQ(cmp, pair_pipe);
EXPECT_EQ(cmp, tuple_pipe);
EXPECT_RANGE_EQ((std::vector{0, 1, 2, 3}), tuple_range | seqan3::views::get<0>);
EXPECT_RANGE_EQ((std::vector{1, 2, 3, 4}), tuple_range | seqan3::views::get<1>);
}

TEST(view_get, concepts)
Expand Down
32 changes: 13 additions & 19 deletions test/unit/range/views/istreambuf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <seqan3/range/views/complement.hpp>
#include <seqan3/range/views/istreambuf.hpp>
#include <seqan3/range/views/take_until.hpp>
#include <seqan3/range/views/to.hpp>
#include <seqan3/test/expect_range_eq.hpp>
#include <seqan3/test/tmp_filename.hpp>
#include <seqan3/utility/char_operations/predicate.hpp>
Expand Down Expand Up @@ -46,39 +45,32 @@ INSTANTIATE_TYPED_TEST_SUITE_P(iterator_fixture, iterator_fixture, test_type, );

TEST(view_istreambuf, basic)
{
using namespace std::literals;
marehr marked this conversation as resolved.
Show resolved Hide resolved

std::string data{"ACGTATATATAT ATATAT TTA \n AUAUAA"};
std::istringstream is{data};

// construct from istream:
auto v1 = seqan3::views::istreambuf(is);
size_t i = 0;
for (auto c : v1)
EXPECT_EQ(c, data[i++]);
EXPECT_EQ(i, data.size());
EXPECT_RANGE_EQ(seqan3::views::istreambuf(is),
data)

// construct from streambuf
is.clear();
is.seekg(0, std::ios::beg);
auto v2 = seqan3::views::istreambuf(*is.rdbuf());
i = 0;
for (auto c : v2)
EXPECT_EQ(c, data[i++]);
EXPECT_EQ(i, data.size());
EXPECT_RANGE_EQ(seqan3::views::istreambuf(*is.rdbuf()),
data)

// combinability
is.clear();
is.seekg(0, std::ios::beg);
auto v3 = seqan3::views::istreambuf(is) | seqan3::views::char_to<seqan3::dna5> | seqan3::views::complement;
std::vector<seqan3::dna5> comp{"TGCATATATATANTATATANAATNNNTATATT"_dna5};
EXPECT_RANGE_EQ(v3, comp);
EXPECT_RANGE_EQ(seqan3::views::istreambuf(is) | seqan3::views::char_to<seqan3::dna5> | seqan3::views::complement,
"TGCATATATATANTATATANAATNNNTATATT"_dna5);

// combinability 2
is.clear();
is.seekg(0, std::ios::beg);
auto v4 = seqan3::views::istreambuf(is) | seqan3::views::take_until(seqan3::is_space);
std::string out2 = v4 | seqan3::views::to<std::string>;
std::string comp2 = "ACGTATATATAT";
EXPECT_RANGE_EQ(out2, comp2);
EXPECT_RANGE_EQ(seqan3::views::istreambuf(is) | seqan3::views::take_until(seqan3::is_space),
"ACGTATATATAT"sv);
}

TEST(view_istreambuf, concepts)
Expand All @@ -100,6 +92,8 @@ TEST(view_istreambuf, concepts)

TEST(view_istreambuf, big_file_stram)
{
using namespace std::literals;

seqan3::test::tmp_filename file_name{"istream_storage"};

{
Expand All @@ -113,7 +107,7 @@ TEST(view_istreambuf, big_file_stram)
while (v.begin() != v.end())
{
EXPECT_RANGE_EQ(v | seqan3::views::take_until_or_throw_and_consume(seqan3::is_char<'\n'>),
std::string_view{"halloballo"});
"halloballo"sv);
}

}
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