Skip to content

Commit

Permalink
[TEST] Add test for too big window size
Browse files Browse the repository at this point in the history
  • Loading branch information
MitraDarja committed Apr 7, 2020
1 parent 3b79860 commit 4e8b34d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 48 deletions.
2 changes: 2 additions & 0 deletions include/seqan3/range/views/minimiser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class minimiser<urng_t>::window_iterator
last_elem{it_end}, window_left{it_start}, window_right{it_start},
num_w_elems{w}
{
if (num_w_elems > std::ranges::distance(window_left, last_elem))
num_w_elems = std::ranges::distance(window_left, last_elem);
if (window_right != last_elem)
get_minimiser();
}
Expand Down
80 changes: 32 additions & 48 deletions test/unit/range/views/view_minimiser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using seqan3::operator""_dna4;
using seqan3::operator""_shape;
using result_t = std::vector<size_t>;

static constexpr auto kmer_view = seqan3::views::kmer_hash(seqan3::ungapped{4});
static constexpr auto gapped_kmer_view = seqan3::views::kmer_hash(0b1001_shape);
Expand All @@ -43,44 +44,26 @@ TYPED_TEST_SUITE(minimiser_view_properties_test, underlying_range_types, );
class minimiser_test : public ::testing::Test
{
protected:
using result_t = std::vector<size_t>;

std::vector<seqan3::dna4> text1{"AAAAAAAAAA"_dna4};
std::vector<seqan3::dna4> text1_short{"AAAAAA"_dna4};
result_t result1{0, 0, 0}; // Same result for ungapped and gapped
result_t result1a{0}; // windows_size == text_size, same result for ungapped and gapped

std::vector<seqan3::dna4> text2{"AC"_dna4};
result_t result2{}; // Same result for ungapped and gapped

std::vector<seqan3::dna4> text2{"ACGTCGACGTTTAG"_dna4};
std::vector<seqan3::dna4> const ctext2{"ACGTCGACGTTTAG"_dna4};
seqan3::bitcompressed_vector<seqan3::dna4> bit_text2{"ACGTCGACGTTTAG"_dna4};
seqan3::bitcompressed_vector<seqan3::dna4> const bit_ctext2{"ACGTCGACGTTTAG"_dna4};
std::list<seqan3::dna4> list_text2{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4, 'C'_dna4,
'G'_dna4, 'T'_dna4, 'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4};
std::list<seqan3::dna4> const list_ctext2{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4,
'C'_dna4, 'G'_dna4, 'T'_dna4, 'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4};
std::forward_list<seqan3::dna4> flist_text2{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4,
'C'_dna4, 'G'_dna4, 'T'_dna4, 'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4};
std::forward_list<seqan3::dna4> const flist_ctext2{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4,
'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'T'_dna4, 'T'_dna4,
'A'_dna4, 'G'_dna4};
result_t ungapped_no_rev2{27, 97, 27}; // ACGT, CGAC, ACGT
result_t gapped_no_rev2{3, 5, 3}; // A--T, C--C, A--T - "-" for gap


std::vector<seqan3::dna4> text3{"AC"_dna4};
result_t result3{}; // Same result for ungapped and gapped

seqan3::bitcompressed_vector<seqan3::dna4> text4{"ACGGCGACGTTTAG"_dna4};
result_t ungapped_no_rev4{26, 97, 27}; // ACGG, CGAC, ACGT
result_t gapped_no_rev4{2, 5, 3}; // A--G, C--C-, A--T "-" for gap
result_t ungapped_no_rev4_stop{26, 97}; // For stop at first T
result_t gapped_no_rev4_stop{2, 5};
seqan3::bitcompressed_vector<seqan3::dna4> text3{"ACGGCGACGTTTAG"_dna4};
result_t ungapped_no_rev3{26, 97, 27}; // ACGG, CGAC, ACGT
result_t gapped_no_rev3{2, 5, 3}; // A--G, C--C-, A--T "-" for gap
result_t ungapped_no_rev3_stop{26, 97}; // For stop at first T
result_t gapped_no_rev3_stop{2, 5};
};

TYPED_TEST(minimiser_view_properties_test, concepts)
{
TypeParam t{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4,
'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4};
auto v = t | kmer_view | minimiser_view;
TypeParam text{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4,
'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4}; // ACGTCGACGTTTAG
auto v = text | kmer_view | minimiser_view;
EXPECT_TRUE(std::ranges::input_range<decltype(v)>);
EXPECT_TRUE(std::ranges::forward_range<decltype(v)>);
EXPECT_TRUE(std::ranges::view<decltype(v)>);
Expand All @@ -89,41 +72,42 @@ TYPED_TEST(minimiser_view_properties_test, concepts)
EXPECT_FALSE((std::ranges::output_range<decltype(v), size_t>));
}

TEST_F(minimiser_test, different_inputs_kmer_hash)
TYPED_TEST(minimiser_view_properties_test, different_inputs_kmer_hash)
{
EXPECT_EQ(ungapped_no_rev2, text2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, ctext2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, bit_text2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, bit_ctext2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, list_text2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, list_ctext2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, flist_text2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev2, flist_ctext2 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
TypeParam text{'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4, 'C'_dna4, 'G'_dna4, 'A'_dna4, 'C'_dna4, 'G'_dna4, 'T'_dna4,
'T'_dna4, 'T'_dna4, 'A'_dna4, 'G'_dna4}; // ACGTCGACGTTTAG
result_t ungapped_no_rev{27, 97, 27}; // ACGT, CGAC, ACGT
result_t gapped_no_rev{3, 5, 3}; // A--T, C--C, A--T - "-" for gap
EXPECT_EQ(ungapped_no_rev, text | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev, text | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
}

TEST_F(minimiser_test, ungapped_kmer_hash)
{
EXPECT_EQ(result1, text1 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(result1, text1_short | kmer_view | minimiser_view2 | seqan3::views::to<result_t>);
// Can be changed to kmer_view once #1699 is merged
EXPECT_EQ(result3, text3 | seqan3::views::kmer_hash(seqan3::ungapped{3}) | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev4, text4 | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(result2, text2 | kmer_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev3, text3 | kmer_view | minimiser_view | seqan3::views::to<result_t>);

}

TEST_F(minimiser_test, gapped_kmer_hash)
{
EXPECT_EQ(result1, text1 | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(result1, text1_short | gapped_kmer_view | minimiser_view2 | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev2, text2 | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
// Can be changed to gapped_kmer_view once #1699 is merged
EXPECT_EQ(result3, text3 | seqan3::views::kmer_hash(0b101_shape) | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev4, text4 | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(result2, text2 | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev3, text3 | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
}

TEST_F(minimiser_test, window_too_big)
{
EXPECT_EQ(result1a, text1 | kmer_view | seqan3::views::minimiser(20) | seqan3::views::to<result_t>);
EXPECT_EQ(result1a, text1 | gapped_kmer_view | seqan3::views::minimiser(20) | seqan3::views::to<result_t>);
}

TEST_F(minimiser_test, combinability)
{
auto stop_at_t = seqan3::views::take_until([] (seqan3::dna4 const x) { return x == 'T'_dna4; });
EXPECT_EQ(ungapped_no_rev4_stop, text4 | stop_at_t | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev4_stop, text4 | stop_at_t | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(ungapped_no_rev3_stop, text3 | stop_at_t | kmer_view | minimiser_view | seqan3::views::to<result_t>);
EXPECT_EQ(gapped_no_rev3_stop, text3 | stop_at_t | gapped_kmer_view | minimiser_view | seqan3::views::to<result_t>);
}

0 comments on commit 4e8b34d

Please sign in to comment.