Skip to content

Commit

Permalink
Merge pull request #1787 from smehringer/search_config_element_test_t…
Browse files Browse the repository at this point in the history
…emplate

[TEST] Introduce a config element test template.
  • Loading branch information
rrahn authored May 11, 2020
2 parents 348e6d8 + bf6c4da commit 6aea6c1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/unit/alignment/configuration/align_config_mode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@
#include <seqan3/alignment/configuration/align_config_mode.hpp>
#include <seqan3/core/algorithm/configuration.hpp>

#include "../../core/algorithm/pipeable_config_element_test_template.hpp"

// ---------------------------------------------------------------------------------------------------------------------
// pipeable_config_element_test template
// ---------------------------------------------------------------------------------------------------------------------

using config_element_types = ::testing::Types<seqan3::align_cfg::mode<seqan3::detail::global_alignment_type>,
seqan3::align_cfg::mode<seqan3::detail::local_alignment_type>>;

INSTANTIATE_TYPED_TEST_SUITE_P(mode, pipeable_config_element_test, config_element_types, );

// ---------------------------------------------------------------------------------------------------------------------
// align_cfg_mode_test
// ---------------------------------------------------------------------------------------------------------------------

template <typename type>
struct align_cfg_mode_test : public ::testing::Test
{};

using test_types = ::testing::Types<seqan3::detail::global_alignment_type, seqan3::detail::local_alignment_type>;
TYPED_TEST_SUITE(align_cfg_mode_test, test_types, );

TYPED_TEST(align_cfg_mode_test, config_element)
{
EXPECT_EQ(seqan3::detail::config_element<seqan3::align_cfg::mode<TypeParam>>, true);
}

TYPED_TEST(align_cfg_mode_test, configuration)
{
{
Expand Down
94 changes: 94 additions & 0 deletions test/unit/core/algorithm/pipeable_config_element_test_template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// -----------------------------------------------------------------------------------------------------
// 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
// -----------------------------------------------------------------------------------------------------

// This file can be used to test the basic functionality of a configuration element

#include <gtest/gtest.h>

#include <seqan3/core/algorithm/configuration.hpp>
#include <seqan3/core/algorithm/pipeable_config_element.hpp>

#include "configuration_mock.hpp"

template <typename format_t>
struct pipeable_config_element_test : public ::testing::Test
{};

TYPED_TEST_SUITE_P(pipeable_config_element_test);

TYPED_TEST_P(pipeable_config_element_test, concept_check)
{
EXPECT_TRUE((seqan3::detail::config_element<TypeParam>));
}

TYPED_TEST_P(pipeable_config_element_test, standard_construction)
{
EXPECT_TRUE((std::is_default_constructible_v<TypeParam>));
EXPECT_TRUE((std::is_copy_constructible_v<TypeParam>));
EXPECT_TRUE((std::is_move_constructible_v<TypeParam>));
EXPECT_TRUE((std::is_copy_assignable_v<TypeParam>));
EXPECT_TRUE((std::is_move_assignable_v<TypeParam>));
}

TYPED_TEST_P(pipeable_config_element_test, configuration_construction)
{
seqan3::configuration cfg{TypeParam{}};
EXPECT_TRUE((std::same_as<decltype(cfg), seqan3::configuration<TypeParam>>));
}

TYPED_TEST_P(pipeable_config_element_test, configuration_assignment)
{
seqan3::configuration cfg = TypeParam{};
EXPECT_TRUE((std::same_as<decltype(cfg), seqan3::configuration<TypeParam>>));
}

// make mock config element foo always pipeable with any other config element
namespace seqan3::detail
{

template <typename t>
struct is_configuration_valid<t, foo> : public std::true_type
{};

template <typename t>
struct is_configuration_valid<foo, t> : public std::true_type
{};

}

TYPED_TEST_P(pipeable_config_element_test, pipeability)
{
TypeParam elem{};
foo dummy{};

{ // lvalue | lvalue
auto cfg = dummy | elem;
EXPECT_TRUE((std::is_same_v<decltype(cfg), seqan3::configuration<foo, TypeParam>>));
}

{ // rvalue | lvalue
auto cfg = TypeParam{} | dummy;
EXPECT_TRUE((std::is_same_v<decltype(cfg), seqan3::configuration<TypeParam, foo>>));
}

{ // lvalue | rvalue
auto cfg = dummy | TypeParam{};
EXPECT_TRUE((std::is_same_v<decltype(cfg), seqan3::configuration<foo, TypeParam>>));
}

{ // rvalue | rvalue
auto cfg = foo{} | TypeParam{};
EXPECT_TRUE((std::is_same_v<decltype(cfg), seqan3::configuration<foo, TypeParam>>));
}
}

REGISTER_TYPED_TEST_SUITE_P(pipeable_config_element_test,
concept_check,
standard_construction,
configuration_construction,
configuration_assignment,
pipeability);

0 comments on commit 6aea6c1

Please sign in to comment.