1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------
#include <gtest/gtest.h>
#include <type_traits>
#include <seqan3/alignment/matrix/alignment_optimum.hpp>
#include <seqan3/core/simd/simd.hpp>
#include <seqan3/core/simd/concept.hpp>
#include <seqan3/test/simd_utility.hpp>
template <typename scalar_t>
struct extract_scalar_type
{
using type = scalar_t;
};
template <seqan3::simd::simd_concept simd_t>
struct extract_scalar_type<simd_t>
{
using type = typename seqan3::simd::simd_traits<simd_t>::scalar_type;
};
template <typename test_t>
struct alignment_optimum_test : public ::testing::Test
{
using scalar_t = typename extract_scalar_type<test_t>::type;
template <typename lhs_t, typename rhs_t>
void expect_eq(lhs_t lhs, rhs_t rhs)
{
if constexpr (seqan3::simd::simd_concept<lhs_t> && seqan3::simd::simd_concept<rhs_t>)
SIMD_EQ(lhs, rhs);
else if constexpr (seqan3::simd::simd_concept<lhs_t> && std::integral<rhs_t>)
SIMD_EQ(lhs, seqan3::simd::fill<lhs_t>(rhs));
else
EXPECT_EQ(lhs, static_cast<lhs_t>(rhs));
}
};
using score_types = ::testing::Types<int32_t, seqan3::simd::simd_type_t<int32_t>>;
TYPED_TEST_SUITE(alignment_optimum_test, score_types, );
TYPED_TEST(alignment_optimum_test, construction)
{
using alignment_optimum_t = seqan3::detail::alignment_optimum<TypeParam>;
EXPECT_TRUE(std::is_nothrow_default_constructible_v<TypeParam>);
EXPECT_TRUE(std::is_nothrow_default_constructible_v<alignment_optimum_t>);
EXPECT_TRUE(std::is_nothrow_copy_constructible_v<alignment_optimum_t>);
EXPECT_TRUE(std::is_nothrow_copy_assignable_v<alignment_optimum_t>);
EXPECT_TRUE(std::is_nothrow_move_constructible_v<alignment_optimum_t>);
EXPECT_TRUE(std::is_nothrow_move_assignable_v<alignment_optimum_t>);
EXPECT_TRUE(std::is_destructible_v<alignment_optimum_t>);
}
TYPED_TEST(alignment_optimum_test, type_deduction)
{
seqan3::detail::alignment_optimum default_optimum{};
EXPECT_TRUE((std::is_same_v<decltype(default_optimum), seqan3::detail::alignment_optimum<int32_t>>));
seqan3::detail::alignment_optimum deduced_optimum{TypeParam{1}, TypeParam{2}, TypeParam{10}};
EXPECT_TRUE((std::is_same_v<decltype(deduced_optimum), seqan3::detail::alignment_optimum<TypeParam>>));
}
TYPED_TEST(alignment_optimum_test, default_constructed)
{
using scalar_t = typename TestFixture::scalar_t;
seqan3::detail::alignment_optimum<TypeParam> default_optimum{};
this->expect_eq(default_optimum.score, std::numeric_limits<scalar_t>::lowest());
this->expect_eq(default_optimum.column_index, 0u);
this->expect_eq(default_optimum.row_index, 0u);
}
TYPED_TEST(alignment_optimum_test, general_construction)
{
seqan3::detail::alignment_optimum optimum{TypeParam{1}, TypeParam{2}, TypeParam{10}};
this->expect_eq(optimum.score, TypeParam{10});
this->expect_eq(optimum.column_index, TypeParam{1});
this->expect_eq(optimum.row_index, TypeParam{2});
}
TYPED_TEST(alignment_optimum_test, update_if_new_optimal_score)
{
using scalar_t = typename TestFixture::scalar_t;
seqan3::detail::alignment_optimum<TypeParam> optimum{};
this->expect_eq(optimum.score, std::numeric_limits<scalar_t>::lowest());
this->expect_eq(optimum.column_index, 0u);
this->expect_eq(optimum.row_index, 0u);
// Bigger score.
optimum.update_if_new_optimal_score(TypeParam{10},
seqan3::detail::column_index_type{1},
seqan3::detail::row_index_type{2});
this->expect_eq(optimum.score, TypeParam{10});
this->expect_eq(optimum.column_index, 1u);
this->expect_eq(optimum.row_index, 2u);
// Same score.
optimum.update_if_new_optimal_score(TypeParam{10},
seqan3::detail::column_index_type{4},
seqan3::detail::row_index_type{5});
this->expect_eq(optimum.score, TypeParam{10});
this->expect_eq(optimum.column_index, 1u);
this->expect_eq(optimum.row_index, 2u);
// Lower score.
optimum.update_if_new_optimal_score(TypeParam{7},
seqan3::detail::column_index_type{4},
seqan3::detail::row_index_type{5});
this->expect_eq(optimum.score, TypeParam{10});
this->expect_eq(optimum.column_index, 1u);
this->expect_eq(optimum.row_index, 2u);
// Mixed score differences
if constexpr (seqan3::simd::simd_concept<TypeParam>)
{ // The following will only work if the simd type has more than one element.
if constexpr (seqan3::simd::simd_traits<TypeParam>::length > 1)
{
TypeParam score_vector{5};
TypeParam cmp_col_index = optimum.column_index;
TypeParam cmp_row_index = optimum.row_index;
score_vector[1] = 11;
cmp_col_index[1] = 3;
cmp_row_index[1] = 7;
optimum.update_if_new_optimal_score(score_vector,
seqan3::detail::column_index_type{3},
seqan3::detail::row_index_type{7});
TypeParam cmp_score_vector{10};
cmp_score_vector[1] = 11;
this->expect_eq(optimum.score, cmp_score_vector);
this->expect_eq(optimum.column_index, cmp_col_index);
this->expect_eq(optimum.row_index, cmp_row_index);
}
}
}
|