generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin | ||
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <hibf/layout/data_store.hpp> // for data_store | ||
|
||
namespace seqan::hibf::layout | ||
{ | ||
|
||
void data_store::validate() const | ||
{ | ||
if (hibf_layout == nullptr) | ||
throw std::invalid_argument{"[HIBF ERROR] data_store::hibf_layout must not be nullptr."}; | ||
|
||
if (kmer_counts == nullptr) | ||
throw std::invalid_argument{"[HIBF ERROR] data_store::kmer_counts must not be nullptr."}; | ||
|
||
if (sketches != nullptr && kmer_counts->size() != sketches->size()) | ||
throw std::invalid_argument{ | ||
"[HIBF ERROR] data_store::kmer_counts and data_store::sketches must have the same size."}; | ||
|
||
if (fpr_correction.empty()) | ||
throw std::invalid_argument{"[HIBF ERROR] data_store::fpr_correction must not be empty."}; | ||
|
||
if (relaxed_fpr_correction <= 0.0 || relaxed_fpr_correction > 1.0) | ||
throw std::invalid_argument{"[HIBF ERROR] data_store::relaxed_fpr_correction must be in (0.0,1.0]."}; | ||
} | ||
|
||
} // namespace seqan::hibf::layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin | ||
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
/*!\file | ||
* \brief Provides EXPECT_THROW_MSG. | ||
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de> | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <hibf/platform.hpp> | ||
|
||
#ifdef EXPECT_THROW_MSG | ||
# warning "EXPECT_THROW_MSG is already defined." | ||
#else | ||
# define EXPECT_THROW_MSG(statement, expected_exception, expected_message) \ | ||
try \ | ||
{ \ | ||
statement; \ | ||
std::string const message = "Expected: " #statement " throws an exception of type " #expected_exception \ | ||
".\n Actual: it throws nothing."; \ | ||
GTEST_NONFATAL_FAILURE_(message.data()); \ | ||
} \ | ||
catch (expected_exception const & exception) \ | ||
{ \ | ||
if (auto result = ::testing::internal::EqHelper::Compare("Expected", \ | ||
"Actual", \ | ||
std::string_view{expected_message}, \ | ||
std::string_view{exception.what()}); \ | ||
!result) \ | ||
{ \ | ||
std::string message = #statement " throws the correct exception, but the description is incorrect.\n"; \ | ||
message += result.failure_message(); \ | ||
GTEST_NONFATAL_FAILURE_(message.data()); \ | ||
} \ | ||
} \ | ||
catch (std::exception const & exception) \ | ||
{ \ | ||
std::string message = "Expected: " #statement " throws an exception of type " #expected_exception ".\n "; \ | ||
message += "Actual: it throws "; \ | ||
message += ::testing::internal::GetTypeName(typeid(exception)); \ | ||
message += " with description \""; \ | ||
message += exception.what(); \ | ||
message += "\"."; \ | ||
GTEST_NONFATAL_FAILURE_(message.data()); \ | ||
} \ | ||
catch (...) \ | ||
{ \ | ||
std::string message = "Expected: " #statement " throws an exception of type " #expected_exception ".\n "; \ | ||
message += "Actual: it throws an unknown exception."; \ | ||
GTEST_NONFATAL_FAILURE_(message.data()); \ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin | ||
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <hibf/layout/data_store.hpp> | ||
#include <hibf/test/expect_throw_msg.hpp> | ||
|
||
TEST(data_store_test, validate) | ||
{ | ||
seqan::hibf::layout::layout layout{}; | ||
std::vector<size_t> kmer_counts(3); | ||
std::vector<seqan::hibf::sketch::hyperloglog> sketches(3); | ||
|
||
// hibf_layout must not be nullptr | ||
{ | ||
seqan::hibf::layout::data_store store{}; | ||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::hibf_layout must not be nullptr."); | ||
} | ||
|
||
// kmer_counts must not be nullptr | ||
{ | ||
seqan::hibf::layout::data_store store{.hibf_layout = &layout}; | ||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::kmer_counts must not be nullptr."); | ||
} | ||
|
||
// kmer_counts and sketches must have the same size | ||
{ | ||
std::vector<seqan::hibf::sketch::hyperloglog> wrong_sketches(2); | ||
|
||
seqan::hibf::layout::data_store store{.hibf_layout = &layout, | ||
.kmer_counts = &kmer_counts, | ||
.sketches = &wrong_sketches}; | ||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::kmer_counts and data_store::sketches must have the same size."); | ||
} | ||
|
||
// fpr_correction must not be empty | ||
{ | ||
seqan::hibf::layout::data_store store{.hibf_layout = &layout, | ||
.kmer_counts = &kmer_counts, | ||
.sketches = &sketches}; | ||
|
||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::fpr_correction must not be empty."); | ||
} | ||
|
||
// relaxed_fpr_correction must be in (0.0,1.0] | ||
{ | ||
seqan::hibf::layout::data_store store{.hibf_layout = &layout, | ||
.kmer_counts = &kmer_counts, | ||
.sketches = &sketches, | ||
.fpr_correction = {1.0, 2.0, 3.0}}; | ||
|
||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::relaxed_fpr_correction must be in (0.0,1.0]."); | ||
|
||
store.relaxed_fpr_correction = 1.01; | ||
EXPECT_THROW_MSG(store.validate(), | ||
std::invalid_argument, | ||
"[HIBF ERROR] data_store::relaxed_fpr_correction must be in (0.0,1.0]."); | ||
|
||
store.relaxed_fpr_correction = 0.5; | ||
EXPECT_NO_THROW(store.validate()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters