Skip to content

Commit 747fe8a

Browse files
committed
tests for clearing and update reallocation
1 parent 0827903 commit 747fe8a

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

include/sketch/sketch_columns.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class FixedSizeSketchColumn {
8787
class ResizeableSketchColumn {
8888

8989
FRIEND_TEST(SketchColumnTestSuite, TestMergeResizing);
90+
FRIEND_TEST(SketchColumnTestSuite, TestClear);
91+
FRIEND_TEST(SketchColumnTestSuite, TestClearMerge);
92+
FRIEND_TEST(SketchColumnTestSuite, TestUpdateReallocation);
9093
private:
9194
Bucket *buckets;
9295
Bucket deterministic_bucket = {0, 0};

test/sketch_test.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ TEST(SketchColumnTestSuite, TestSketchColumnMergeMany) {
543543
}
544544

545545
// verify logical equivalence between resizeable and fixed-size sketch columns. given the same seed and inputs, they should have the same output behavior.
546-
// note that I (david) changed the sample algorithm for fixed-size sketch columns for this test to work.
547546
TEST(SketchColumnTestSuite, TestLogicalEquivalence) {
548547
for (size_t i = 0; i < 100; i++) {
549548
auto seed = get_seed();
@@ -594,4 +593,68 @@ TEST(SketchColumnTestSuite, TestDepthMonotonicity) {
594593
current_depth = new_depth;
595594
}
596595
}
596+
}
597+
598+
// make sure that clearing the sketch zeroes everything out
599+
TEST(SketchColumnTestSuite, TestClear) {
600+
auto seed = get_seed();
601+
size_t capacity = 32;
602+
ResizeableSketchColumn column(capacity, seed);
603+
for (size_t i = 0; i < (1 << 20); i++) {
604+
column.update(i);
605+
}
606+
auto sample = column.sample();
607+
ASSERT_EQ(sample.result, GOOD);
608+
column.clear();
609+
for (size_t i = 0; i < capacity; i++) {
610+
bool good = Bucket_Boruvka::is_empty(column.buckets[i]);
611+
ASSERT_EQ(good, true);
612+
}
613+
}
614+
615+
// make sure that if we merge two sketches, clearing one doesn't affect the other
616+
TEST(SketchColumnTestSuite, TestClearMerge) {
617+
auto seed = get_seed();
618+
size_t capacity = 32;
619+
ResizeableSketchColumn column1(capacity, seed);
620+
ResizeableSketchColumn column2(capacity, seed);
621+
for (size_t i = 0; i < (1 << 20); i++) {
622+
column1.update(i);
623+
column2.update(i + (1 << 21));
624+
}
625+
column1.merge(column2);
626+
column2.clear();
627+
for (size_t i = 0; i < capacity; i++) {
628+
bool good = Bucket_Boruvka::is_empty(column2.buckets[i]);
629+
ASSERT_EQ(good, true);
630+
}
631+
auto sample = column1.sample();
632+
ASSERT_EQ(sample.result, GOOD);
633+
634+
// now test the same thing, but clearing the merged-into column instead
635+
ResizeableSketchColumn column3(capacity, seed);
636+
ResizeableSketchColumn column4(capacity, seed);
637+
for (size_t i = 0; i < (1 << 20); i++) {
638+
column3.update(i);
639+
column4.update(i + (1 << 21));
640+
}
641+
column3.merge(column4);
642+
column3.clear();
643+
for (size_t i = 0; i < capacity; i++) {
644+
bool empty = Bucket_Boruvka::is_empty(column3.buckets[i]);
645+
ASSERT_EQ(empty, true);
646+
}
647+
auto sample2 = column4.sample();
648+
ASSERT_EQ(sample2.result, GOOD);
649+
}
650+
651+
// test whether updates that are too deep cause reallocation to increase capacity
652+
TEST(SketchColumnTestSuite, TestUpdateReallocation) {
653+
auto seed = get_seed();
654+
size_t capacity = 6;
655+
ResizeableSketchColumn column(capacity, seed);
656+
for (size_t i = 0; i < (1 << 10); i++) {
657+
column.update(i);
658+
}
659+
ASSERT_GE(column.capacity, capacity);
597660
}

0 commit comments

Comments
 (0)