You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2020/07/02 21:19:41 UTC
[incubator-datasketches-cpp] branch tuple_sketch updated: more
serde tests
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch tuple_sketch
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
The following commit(s) were added to refs/heads/tuple_sketch by this push:
new 90fcd2c more serde tests
90fcd2c is described below
commit 90fcd2cdc96ea19f8aa9ef614dae27611feef594
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Thu Jul 2 14:19:26 2020 -0700
more serde tests
---
common/test/test_type.hpp | 10 +++++-----
tuple/test/tuple_sketch_allocation_test.cpp | 4 ++++
tuple/test/tuple_sketch_test.cpp | 21 +++++++++++++++------
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/common/test/test_type.hpp b/common/test/test_type.hpp
index 1651c9a..cbd1a2e 100644
--- a/common/test/test_type.hpp
+++ b/common/test/test_type.hpp
@@ -75,23 +75,23 @@ struct test_type_less {
};
struct test_type_serde {
- void serialize(std::ostream& os, const test_type* items, unsigned num) {
+ void serialize(std::ostream& os, const test_type* items, unsigned num) const {
for (unsigned i = 0; i < num; i++) {
const int value = items[i].get_value();
os.write((char*)&value, sizeof(value));
}
}
- void deserialize(std::istream& is, test_type* items, unsigned num) {
+ void deserialize(std::istream& is, test_type* items, unsigned num) const {
for (unsigned i = 0; i < num; i++) {
int value;
is.read((char*)&value, sizeof(value));
new (&items[i]) test_type(value);
}
}
- size_t size_of_item(const test_type&) {
+ size_t size_of_item(const test_type&) const {
return sizeof(int);
}
- size_t serialize(void* ptr, size_t capacity, const test_type* items, unsigned num) {
+ size_t serialize(void* ptr, size_t capacity, const test_type* items, unsigned num) const {
const size_t bytes_written = sizeof(int) * num;
check_memory_size(bytes_written, capacity);
for (unsigned i = 0; i < num; ++i) {
@@ -100,7 +100,7 @@ struct test_type_serde {
}
return bytes_written;
}
- size_t deserialize(const void* ptr, size_t capacity, test_type* items, unsigned num) {
+ size_t deserialize(const void* ptr, size_t capacity, test_type* items, unsigned num) const {
const size_t bytes_read = sizeof(int) * num;
check_memory_size(bytes_read, capacity);
for (unsigned i = 0; i < num; ++i) {
diff --git a/tuple/test/tuple_sketch_allocation_test.cpp b/tuple/test/tuple_sketch_allocation_test.cpp
index efbacc4..e6d62e0 100644
--- a/tuple/test/tuple_sketch_allocation_test.cpp
+++ b/tuple/test/tuple_sketch_allocation_test.cpp
@@ -56,6 +56,10 @@ TEST_CASE("tuple sketch with test allocator: exact mode", "[tuple_sketch]") {
++count;
}
REQUIRE(count == update_sketch.get_num_retained());
+
+ auto bytes = compact_sketch.serialize();
+ auto deserialized_sketch = compact_tuple_sketch<int, test_allocator<int>>::deserialize(bytes.data(), bytes.size());
+ REQUIRE(deserialized_sketch.get_estimate() == compact_sketch.get_estimate());
}
REQUIRE(test_allocator_total_bytes == 0);
REQUIRE(test_allocator_net_allocations == 0);
diff --git a/tuple/test/tuple_sketch_test.cpp b/tuple/test/tuple_sketch_test.cpp
index 2117eb7..a50cb48 100644
--- a/tuple/test/tuple_sketch_test.cpp
+++ b/tuple/test/tuple_sketch_test.cpp
@@ -166,14 +166,23 @@ struct test_type_replace_policy {
};
TEST_CASE("tuple sketch: test type with replace policy", "[tuple_sketch]") {
- auto sketch = update_tuple_sketch<test_type, test_type, test_type_replace_policy>::builder().build();
+ auto update_sketch = update_tuple_sketch<test_type, test_type, test_type_replace_policy>::builder().build();
test_type a(1);
- sketch.update(1, a); // this should copy
- sketch.update(2, 2); // this should move
- sketch.update(1, 2); // this should move
+ update_sketch.update(1, a); // this should copy
+ update_sketch.update(2, 2); // this should move
+ update_sketch.update(1, 2); // this should move
// std::cout << sketch.to_string(true);
- REQUIRE(sketch.get_num_retained() == 2);
- for (const auto& entry: sketch) {
+ REQUIRE(update_sketch.get_num_retained() == 2);
+ for (const auto& entry: update_sketch) {
+ REQUIRE(entry.second.get_value() == 2);
+ }
+
+ auto compact_sketch = update_sketch.compact();
+ auto bytes = compact_sketch.serialize(0, test_type_serde());
+ auto deserialized_sketch = compact_tuple_sketch<test_type>::deserialize(bytes.data(), bytes.size(),
+ DEFAULT_SEED, test_type_serde());
+ REQUIRE(deserialized_sketch.get_num_retained() == 2);
+ for (const auto& entry: deserialized_sketch) {
REQUIRE(entry.second.get_value() == 2);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org