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

[FEATURE] Add layout::clear() function. #176

Merged
merged 2 commits into from
Nov 28, 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
2 changes: 2 additions & 0 deletions include/hibf/layout/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct layout
void read_from(std::istream & stream);
void write_to(std::ostream & stream) const;

void clear();

size_t top_level_max_bin_id{};
std::vector<max_bin> max_bins{};
std::vector<user_bin> user_bins{};
Expand Down
7 changes: 7 additions & 0 deletions src/layout/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ void seqan::hibf::layout::layout::write_to(std::ostream & stream) const
stream << user_bin << '\n';
}

void seqan::hibf::layout::layout::clear()
{
top_level_max_bin_id = 0;
max_bins.clear();
user_bins.clear();
}

} // namespace seqan::hibf::layout
51 changes: 31 additions & 20 deletions test/unit/hibf/layout/layout_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ TEST(layout_test, printing_user_bins)
EXPECT_EQ(ss.str(), expected);
}

static std::string const layout_file{
R"layout_file(#TOP_LEVEL_IBF fullest_technical_bin_idx:111
#LOWER_LEVEL_IBF_0 fullest_technical_bin_idx:0
#LOWER_LEVEL_IBF_2 fullest_technical_bin_idx:2
#LOWER_LEVEL_IBF_1;2;3;4 fullest_technical_bin_idx:22
#USER_BIN_IDX TECHNICAL_BIN_INDICES NUMBER_OF_TECHNICAL_BINS
7 0 1
4 1;0 1;22
5 1;2;3;4;22 1;1;1;1;21
)layout_file"};

TEST(layout_test, write_to)
{
std::stringstream ss{};
Expand All @@ -70,30 +81,12 @@ TEST(layout_test, write_to)

layout.write_to(ss);

std::string expected = R"layout_file(#TOP_LEVEL_IBF fullest_technical_bin_idx:111
#LOWER_LEVEL_IBF_0 fullest_technical_bin_idx:0
#LOWER_LEVEL_IBF_2 fullest_technical_bin_idx:2
#LOWER_LEVEL_IBF_1;2;3;4 fullest_technical_bin_idx:22
#USER_BIN_IDX TECHNICAL_BIN_INDICES NUMBER_OF_TECHNICAL_BINS
7 0 1
4 1;0 1;22
5 1;2;3;4;22 1;1;1;1;21
)layout_file";

EXPECT_EQ(ss.str(), expected);
EXPECT_EQ(ss.str(), layout_file);
}

TEST(layout_test, read_from)
{
std::stringstream ss{R"layout_file(#TOP_LEVEL_IBF fullest_technical_bin_idx:111
#LOWER_LEVEL_IBF_0 fullest_technical_bin_idx:0
#LOWER_LEVEL_IBF_2 fullest_technical_bin_idx:2
#LOWER_LEVEL_IBF_1;2;3;4 fullest_technical_bin_idx:22
#USER_BIN_IDX TECHNICAL_BIN_INDICES NUMBER_OF_TECHNICAL_BINS
7 0 1
4 1;0 1;22
5 1;2;3;4;22 1;1;1;1;21
)layout_file"};
std::stringstream ss{layout_file};

seqan::hibf::layout::layout layout;
layout.read_from(ss);
Expand All @@ -106,3 +99,21 @@ TEST(layout_test, read_from)
EXPECT_EQ(layout.user_bins[1], (seqan::hibf::layout::layout::user_bin{std::vector<size_t>{1}, 0, 22, 4}));
EXPECT_EQ(layout.user_bins[2], (seqan::hibf::layout::layout::user_bin{std::vector<size_t>{1, 2, 3, 4}, 22, 21, 5}));
}

TEST(layout_test, clear)
{
std::stringstream ss{layout_file};

seqan::hibf::layout::layout layout;
layout.read_from(ss);

ASSERT_NE(layout.top_level_max_bin_id, 0);
ASSERT_FALSE(layout.max_bins.empty());
ASSERT_FALSE(layout.user_bins.empty());

layout.clear();

EXPECT_EQ(layout.top_level_max_bin_id, 0);
EXPECT_TRUE(layout.max_bins.empty());
EXPECT_TRUE(layout.user_bins.empty());
}