Skip to content

Commit

Permalink
rtree: test serialization, fix std::vector tuple test leak
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Dec 5, 2024
1 parent 1777479 commit c0a48d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions include/cista/containers/rtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct basic_rtree {
using coord_t = array<NumType, Dims>;

struct rect {
inline bool feq(NumType a, NumType b) { return !(a < b || a > b); }
static inline bool feq(NumType a, NumType b) { return !(a < b || a > b); }

NumType united_area(rect const& other_rect) const noexcept {
auto result = NumType{1};
Expand Down Expand Up @@ -112,7 +112,7 @@ struct basic_rtree {
return true;
}

bool coord_t_equal(coord_t const& coord_1, coord_t const& coord_2) {
bool coord_t_equal(coord_t const& coord_1, coord_t const& coord_2) const {
for (size_t i = 0; i < Dims; ++i) {
if (!feq(coord_1[i], coord_2[i])) {
return false;
Expand Down
23 changes: 15 additions & 8 deletions test/rtree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,24 @@ TEST_SUITE("rtree") {
std::vector<cista::rtree<size_t>::rect> rand_rects_list;
srand(static_cast<unsigned>(time(nullptr)));

for (int i = 0; i < N; ++i) {
fill_rand_rect(rand_rects_list);
}
auto buf = cista::byte_buf{};

cista::rtree<size_t> rt;
for (size_t i = 0; i < rand_rects_list.size(); ++i) {
cista::rtree<size_t>::coord_t min = rand_rects_list[i].min_;
cista::rtree<size_t>::coord_t max = rand_rects_list[i].max_;
rt.insert(min, max, i);
{
for (int i = 0; i < N; ++i) {
fill_rand_rect(rand_rects_list);
}

cista::rtree<size_t> rt;
for (size_t i = 0; i < rand_rects_list.size(); ++i) {
cista::rtree<size_t>::coord_t min = rand_rects_list[i].min_;
cista::rtree<size_t>::coord_t max = rand_rects_list[i].max_;
rt.insert(min, max, i);
}

buf = cista::serialize(rt);
}

auto const& rt = *cista::deserialize<cista::rtree<size_t>>(buf);
for (size_t i = 0; i < rand_rects_list.size(); ++i) {
cista::rtree<size_t>::coord_t min = rand_rects_list[i].min_;
cista::rtree<size_t>::coord_t max = rand_rects_list[i].max_;
Expand Down
12 changes: 5 additions & 7 deletions test/std_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ TEST_CASE("vector test") {
TEST_CASE("vector tuple test") {
namespace data = cista::offset;

using T = cista::tuple<data::string, data::vector<char>,
data::vector<data::vector<char>>, std::vector<char>,
data::vector<std::vector<char>>,
std::vector<data::vector<char>>, double>;
using T =
cista::tuple<data::string, data::vector<char>,
data::vector<data::vector<char>>, std::vector<char>, double>;

auto buf = cista::byte_buf{};
{
Expand All @@ -107,8 +106,6 @@ TEST_CASE("vector tuple test") {
{'w', 'h', 'a', 't', '?'},
{{'a'}, {'v', 'a', 'l', 'u', 'e'}},
{'w', 'h', 'a', 't', '?'},
{{'a'}, {'v', 'a', 'l', 'u', 'e'}},
{{'a'}, {'v', 'a', 'l', 'u', 'e'}},
3.14,
};
buf = cista::serialize(value);
Expand All @@ -117,5 +114,6 @@ TEST_CASE("vector tuple test") {
auto tuple = cista::deserialize<T>(buf);
CHECK_EQ(0, std::strncmp("what?", cista::get<3>(*tuple).data(), 5));

tuple->~T();
using X = std::vector<char>;
cista::get<3>(*tuple).~X();
}

0 comments on commit c0a48d8

Please sign in to comment.