Skip to content

Commit

Permalink
[TEST] add test for alphabet customisation point
Browse files Browse the repository at this point in the history
  • Loading branch information
h-2 committed May 2, 2019
1 parent 513e81c commit 3dedd86
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unit/alphabet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectories()
seqan3_test(custom_alphabet_test.cpp)
69 changes: 69 additions & 0 deletions test/unit/alphabet/custom_alphabet_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2019, 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 <seqan3/core/platform.hpp>
#include <cereal/types/common.hpp>

#include "alphabet_test_template.hpp"
#include "alphabet_constexpr_test_template.hpp"

// Tests the ADL-capabilities of the alphabet customisation point objects

namespace my_namespace
{

enum class my_alph
{
ZERO,
ONE,
TWO
};

constexpr size_t alphabet_size(my_alph const &) noexcept
{
return 3;
}

constexpr size_t to_rank(my_alph const a) noexcept
{
return static_cast<size_t>(a);
}

constexpr my_alph & assign_rank_to(size_t const r, my_alph & a) noexcept
{
switch (r)
{
case 0: a = my_alph::ZERO; return a;
case 1: a = my_alph::ONE; return a;
default: a = my_alph::TWO; return a;
}
}

constexpr char to_char(my_alph const a) noexcept
{
switch (a)
{
case my_alph::ZERO: return '0';
case my_alph::ONE: return '1';
default: return '2';
}
}

constexpr my_alph & assign_char_to(char const c, my_alph & a) noexcept
{
switch (c)
{
case '0': a = my_alph::ZERO; return a;
case '1': a = my_alph::ONE; return a;
default: a = my_alph::TWO; return a;
}
}

}

INSTANTIATE_TYPED_TEST_CASE_P(my_alph, alphabet, my_namespace::my_alph);
INSTANTIATE_TYPED_TEST_CASE_P(my_alph, alphabet_constexpr, my_namespace::my_alph);

0 comments on commit 3dedd86

Please sign in to comment.