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] Add serialisation tests #165

Merged
merged 1 commit into from
Nov 9, 2023
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
1 change: 1 addition & 0 deletions include/hibf/cereal/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <hibf/platform.hpp>

#include <cereal/macros.hpp> // for CEREAL_LOAD_FUNCTION_NAME, CEREAL_SAVE_FUNCTION_NAME
#include <cereal/types/string.hpp>

namespace cereal
{
Expand Down
17 changes: 17 additions & 0 deletions include/hibf/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ struct config
*/
void validate_and_set_defaults();

//!\brief Two configs are equal if all options, except seqan::hibf::config::input_fn, are equal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just because input_fn cannot really be checked right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it cant be compared, expect to nullptr. You could compare the addresses of the function that will be called, but I don't think that is what we want

constexpr bool operator==(config const & other) const
{
// clang-format off
return number_of_user_bins == other.number_of_user_bins &&
maximum_fpr == other.maximum_fpr &&
relaxed_fpr == other.relaxed_fpr &&
threads == other.threads &&
sketch_bits == other.sketch_bits &&
tmax == other.tmax &&
alpha == other.alpha &&
max_rearrangement_ratio == other.max_rearrangement_ratio &&
disable_estimate_union == other.disable_estimate_union &&
disable_rearrangement == other.disable_rearrangement;
// clang-format on
}

private:
friend class cereal::access;

Expand Down
1 change: 1 addition & 0 deletions test/unit/hibf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ hibf_test (bit_vector_test.cpp)
hibf_test (config_test.cpp)
hibf_test (hierarchical_interleaved_bloom_filter_test.cpp)
hibf_test (interleaved_bloom_filter_test.cpp)
hibf_test (path_test.cpp)
hibf_test (print_test.cpp)
hibf_test (timer_test.cpp)
16 changes: 16 additions & 0 deletions test/unit/hibf/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string_view> // for string_view

#include <hibf/config.hpp> // for config, insert_iterator
#include <hibf/test/cereal.hpp>

TEST(config_test, write_to)
{
Expand Down Expand Up @@ -319,3 +320,18 @@ TEST(config_test, validate_and_set_defaults)
EXPECT_EQ((testing::internal::GetCapturedStderr()), "");
}
}

TEST(config_test, serialisation)
{
seqan::hibf::config config{.number_of_user_bins = 123456789,
.number_of_hash_functions = 4,
.maximum_fpr = 0.0001,
.threads = 31,
.sketch_bits = 8,
.tmax = 128,
.alpha = 1.0,
.max_rearrangement_ratio = 0.333,
.disable_estimate_union = true,
.disable_rearrangement = false};
seqan::hibf::test::test_serialisation(std::move(config));
}
14 changes: 14 additions & 0 deletions test/unit/hibf/path_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2006-2023, Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2023, Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause

#include <gtest/gtest.h>

#include <hibf/cereal/path.hpp>
#include <hibf/test/cereal.hpp>

TEST(path_test, serialisation)
{
std::filesystem::path path{"/some/random/path.txt"};
seqan::hibf::test::test_serialisation(std::move(path));
Comment on lines +12 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you testing the std lib?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are providing the cereal overload

}