aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/histogram/hdr/histogram_iter_ut.cpp
diff options
context:
space:
mode:
authorSergey Polovko <sergey@polovko.me>2022-02-10 16:47:02 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:02 +0300
commit3e0b762a82514bac89c1dd6ea7211e381d8aa248 (patch)
treec2d1b379ecaf05ca8f11ed0b5da9d1a950e6e554 /library/cpp/histogram/hdr/histogram_iter_ut.cpp
parentab3783171cc30e262243a0227c86118f7080c896 (diff)
downloadydb-3e0b762a82514bac89c1dd6ea7211e381d8aa248.tar.gz
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/histogram/hdr/histogram_iter_ut.cpp')
-rw-r--r--library/cpp/histogram/hdr/histogram_iter_ut.cpp402
1 files changed, 201 insertions, 201 deletions
diff --git a/library/cpp/histogram/hdr/histogram_iter_ut.cpp b/library/cpp/histogram/hdr/histogram_iter_ut.cpp
index 9c291a2547..7a843dec65 100644
--- a/library/cpp/histogram/hdr/histogram_iter_ut.cpp
+++ b/library/cpp/histogram/hdr/histogram_iter_ut.cpp
@@ -1,210 +1,210 @@
-#include "histogram_iter.h"
-
+#include "histogram_iter.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NHdr;
-
+
+using namespace NHdr;
+
Y_UNIT_TEST_SUITE(THistogramIterTest) {
Y_UNIT_TEST(RecordedValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValues(1000, 1000));
- UNIT_ASSERT(h.RecordValue(1000 * 1000));
-
- int index = 0;
- TRecordedValuesIterator it(h);
-
- while (it.Next()) {
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1000);
- UNIT_ASSERT_EQUAL(countInStep, 1000);
- } else if (index == 1) {
- UNIT_ASSERT_EQUAL(countInBucket, 1);
- UNIT_ASSERT_EQUAL(countInStep, 1);
- } else {
- UNIT_FAIL("unexpected index value: " << index);
- }
-
- index++;
- }
-
- UNIT_ASSERT_EQUAL(index, 2);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValues(1000, 1000));
+ UNIT_ASSERT(h.RecordValue(1000 * 1000));
+
+ int index = 0;
+ TRecordedValuesIterator it(h);
+
+ while (it.Next()) {
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1000);
+ UNIT_ASSERT_EQUAL(countInStep, 1000);
+ } else if (index == 1) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1);
+ UNIT_ASSERT_EQUAL(countInStep, 1);
+ } else {
+ UNIT_FAIL("unexpected index value: " << index);
+ }
+
+ index++;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 2);
+ }
+
Y_UNIT_TEST(CorrectedRecordedValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
- UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
-
- int index = 0;
- i64 totalCount = 0;
- TRecordedValuesIterator it(h);
-
- while (it.Next()) {
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1001);
- UNIT_ASSERT_EQUAL(countInStep, 1001);
- } else {
- UNIT_ASSERT(countInBucket >= 1);
- UNIT_ASSERT(countInStep >= 1);
- }
- index++;
- totalCount += countInStep;
- }
-
- UNIT_ASSERT_EQUAL(index, 1000);
- UNIT_ASSERT_EQUAL(totalCount, 2000);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
+ UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
+
+ int index = 0;
+ i64 totalCount = 0;
+ TRecordedValuesIterator it(h);
+
+ while (it.Next()) {
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1001);
+ UNIT_ASSERT_EQUAL(countInStep, 1001);
+ } else {
+ UNIT_ASSERT(countInBucket >= 1);
+ UNIT_ASSERT(countInStep >= 1);
+ }
+ index++;
+ totalCount += countInStep;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 1000);
+ UNIT_ASSERT_EQUAL(totalCount, 2000);
+ }
+
Y_UNIT_TEST(LinearValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValues(1000, 1000));
- UNIT_ASSERT(h.RecordValue(1000 * 1000));
-
- int index = 0;
- TLinearIterator it(h, 1000);
-
- while (it.Next()) {
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1000);
- UNIT_ASSERT_EQUAL(countInStep, 1000);
- } else if (index == 999) {
- UNIT_ASSERT_EQUAL(countInBucket, 1);
- UNIT_ASSERT_EQUAL(countInStep, 1);
- } else {
- UNIT_ASSERT_EQUAL(countInBucket, 0);
- UNIT_ASSERT_EQUAL(countInStep, 0);
- }
-
- index++;
- }
-
- UNIT_ASSERT_EQUAL(index, 1000);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValues(1000, 1000));
+ UNIT_ASSERT(h.RecordValue(1000 * 1000));
+
+ int index = 0;
+ TLinearIterator it(h, 1000);
+
+ while (it.Next()) {
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1000);
+ UNIT_ASSERT_EQUAL(countInStep, 1000);
+ } else if (index == 999) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1);
+ UNIT_ASSERT_EQUAL(countInStep, 1);
+ } else {
+ UNIT_ASSERT_EQUAL(countInBucket, 0);
+ UNIT_ASSERT_EQUAL(countInStep, 0);
+ }
+
+ index++;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 1000);
+ }
+
Y_UNIT_TEST(CorrectLinearValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
- UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
-
- int index = 0;
- i64 totalCount = 0;
- TLinearIterator it(h, 1000);
-
- while (it.Next()) {
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
-
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1001);
- UNIT_ASSERT_EQUAL(countInStep, 1001);
- } else {
- UNIT_ASSERT_EQUAL(countInBucket, 1);
- UNIT_ASSERT_EQUAL(countInStep, 1);
- }
-
- index++;
- totalCount += countInStep;
- }
-
- UNIT_ASSERT_EQUAL(index, 1000);
- UNIT_ASSERT_EQUAL(totalCount, 2000);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
+ UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
+
+ int index = 0;
+ i64 totalCount = 0;
+ TLinearIterator it(h, 1000);
+
+ while (it.Next()) {
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1001);
+ UNIT_ASSERT_EQUAL(countInStep, 1001);
+ } else {
+ UNIT_ASSERT_EQUAL(countInBucket, 1);
+ UNIT_ASSERT_EQUAL(countInStep, 1);
+ }
+
+ index++;
+ totalCount += countInStep;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 1000);
+ UNIT_ASSERT_EQUAL(totalCount, 2000);
+ }
+
Y_UNIT_TEST(LogarithmicValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValues(1000, 1000));
- UNIT_ASSERT(h.RecordValue(1000 * 1000));
-
- int index = 0;
- i64 expectedValue = 1000;
- TLogarithmicIterator it(h, 1000, 2.0);
-
- while (it.Next()) {
- i64 value = it.GetValue();
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
-
- UNIT_ASSERT_EQUAL(value, expectedValue);
-
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1000);
- UNIT_ASSERT_EQUAL(countInStep, 1000);
- } else if (index == 10) {
- UNIT_ASSERT_EQUAL(countInBucket, 0);
- UNIT_ASSERT_EQUAL(countInStep, 1);
- } else {
- UNIT_ASSERT_EQUAL(countInBucket, 0);
- UNIT_ASSERT_EQUAL(countInStep, 0);
- }
-
- index++;
- expectedValue *= 2;
- }
-
- UNIT_ASSERT_EQUAL(index, 11);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValues(1000, 1000));
+ UNIT_ASSERT(h.RecordValue(1000 * 1000));
+
+ int index = 0;
+ i64 expectedValue = 1000;
+ TLogarithmicIterator it(h, 1000, 2.0);
+
+ while (it.Next()) {
+ i64 value = it.GetValue();
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+
+ UNIT_ASSERT_EQUAL(value, expectedValue);
+
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1000);
+ UNIT_ASSERT_EQUAL(countInStep, 1000);
+ } else if (index == 10) {
+ UNIT_ASSERT_EQUAL(countInBucket, 0);
+ UNIT_ASSERT_EQUAL(countInStep, 1);
+ } else {
+ UNIT_ASSERT_EQUAL(countInBucket, 0);
+ UNIT_ASSERT_EQUAL(countInStep, 0);
+ }
+
+ index++;
+ expectedValue *= 2;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 11);
+ }
+
Y_UNIT_TEST(CorrectedLogarithmicValues) {
- THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
- UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
- UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
-
- int index = 0;
- i64 totalCount = 0;
- i64 expectedValue = 1000;
- TLogarithmicIterator it(h, 1000, 2.0);
-
- while (it.Next()) {
- i64 value = it.GetValue();
- i64 countInBucket = it.GetCount();
- i64 countInStep = it.GetCountAddedInThisIterationStep();
-
- UNIT_ASSERT_EQUAL(value, expectedValue);
-
- if (index == 0) {
- UNIT_ASSERT_EQUAL(countInBucket, 1001);
- UNIT_ASSERT_EQUAL(countInStep, 1001);
- }
-
- index++;
- totalCount += countInStep;
- expectedValue *= 2;
- }
-
- UNIT_ASSERT_EQUAL(index, 11);
- UNIT_ASSERT_EQUAL(totalCount, 2000);
- }
-
+ THistogram h(TDuration::Hours(1).MicroSeconds(), 3);
+ UNIT_ASSERT(h.RecordValuesWithExpectedInterval(1000, 1000, 1000));
+ UNIT_ASSERT(h.RecordValueWithExpectedInterval(1000 * 1000, 1000));
+
+ int index = 0;
+ i64 totalCount = 0;
+ i64 expectedValue = 1000;
+ TLogarithmicIterator it(h, 1000, 2.0);
+
+ while (it.Next()) {
+ i64 value = it.GetValue();
+ i64 countInBucket = it.GetCount();
+ i64 countInStep = it.GetCountAddedInThisIterationStep();
+
+ UNIT_ASSERT_EQUAL(value, expectedValue);
+
+ if (index == 0) {
+ UNIT_ASSERT_EQUAL(countInBucket, 1001);
+ UNIT_ASSERT_EQUAL(countInStep, 1001);
+ }
+
+ index++;
+ totalCount += countInStep;
+ expectedValue *= 2;
+ }
+
+ UNIT_ASSERT_EQUAL(index, 11);
+ UNIT_ASSERT_EQUAL(totalCount, 2000);
+ }
+
Y_UNIT_TEST(LinearIterBucketsCorrectly) {
- THistogram h(255, 2);
- UNIT_ASSERT(h.RecordValue(193));
- UNIT_ASSERT(h.RecordValue(255));
- UNIT_ASSERT(h.RecordValue(0));
- UNIT_ASSERT(h.RecordValue(1));
- UNIT_ASSERT(h.RecordValue(64));
- UNIT_ASSERT(h.RecordValue(128));
-
- int index = 0;
- i64 totalCount = 0;
- TLinearIterator it(h, 64);
-
- while (it.Next()) {
- if (index == 0) {
- // change after iterator was created
- UNIT_ASSERT(h.RecordValue(2));
- }
-
- index++;
- totalCount += it.GetCountAddedInThisIterationStep();
- }
-
- UNIT_ASSERT_EQUAL(index, 4);
- UNIT_ASSERT_EQUAL(totalCount, 6);
- }
-}
+ THistogram h(255, 2);
+ UNIT_ASSERT(h.RecordValue(193));
+ UNIT_ASSERT(h.RecordValue(255));
+ UNIT_ASSERT(h.RecordValue(0));
+ UNIT_ASSERT(h.RecordValue(1));
+ UNIT_ASSERT(h.RecordValue(64));
+ UNIT_ASSERT(h.RecordValue(128));
+
+ int index = 0;
+ i64 totalCount = 0;
+ TLinearIterator it(h, 64);
+
+ while (it.Next()) {
+ if (index == 0) {
+ // change after iterator was created
+ UNIT_ASSERT(h.RecordValue(2));
+ }
+
+ index++;
+ totalCount += it.GetCountAddedInThisIterationStep();
+ }
+
+ UNIT_ASSERT_EQUAL(index, 4);
+ UNIT_ASSERT_EQUAL(totalCount, 6);
+ }
+}