Skip to content

Commit

Permalink
Merge pull request #176 from smehringer/layout_clear
Browse files Browse the repository at this point in the history
[FEATURE] Add layout::clear() function.
  • Loading branch information
eseiler authored Nov 28, 2023
2 parents 537e83e + ac75451 commit b068f7e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
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());
}

1 comment on commit b068f7e

@vercel
Copy link

@vercel vercel bot commented on b068f7e Nov 28, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

hibf – ./

hibf-git-main-seqan.vercel.app
hibf-seqan.vercel.app
hibf.vercel.app

Please sign in to comment.