diff options
| author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
|---|---|---|
| committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 | 
| commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
| tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/messagebus/duration_histogram_ut.cpp | |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/messagebus/duration_histogram_ut.cpp')
| -rw-r--r-- | library/cpp/messagebus/duration_histogram_ut.cpp | 38 | 
1 files changed, 38 insertions, 0 deletions
diff --git a/library/cpp/messagebus/duration_histogram_ut.cpp b/library/cpp/messagebus/duration_histogram_ut.cpp new file mode 100644 index 00000000000..01bcc095e99 --- /dev/null +++ b/library/cpp/messagebus/duration_histogram_ut.cpp @@ -0,0 +1,38 @@ +#include <library/cpp/testing/unittest/registar.h> + +#include "duration_histogram.h" + +Y_UNIT_TEST_SUITE(TDurationHistogramTest) { +    Y_UNIT_TEST(BucketFor) { +        UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(0))); +        UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(1))); +        UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(900))); +        UNIT_ASSERT_VALUES_EQUAL(1u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(1500))); +        UNIT_ASSERT_VALUES_EQUAL(2u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(2500))); + +        unsigned sb = TDurationHistogram::SecondBoundary; + +        UNIT_ASSERT_VALUES_EQUAL(sb - 1, TDurationHistogram::BucketFor(TDuration::MilliSeconds(999))); +        UNIT_ASSERT_VALUES_EQUAL(sb, TDurationHistogram::BucketFor(TDuration::MilliSeconds(1000))); +        UNIT_ASSERT_VALUES_EQUAL(sb, TDurationHistogram::BucketFor(TDuration::MilliSeconds(1001))); + +        UNIT_ASSERT_VALUES_EQUAL(TDurationHistogram::Buckets - 1, TDurationHistogram::BucketFor(TDuration::Hours(1))); +    } + +    Y_UNIT_TEST(Simple) { +        TDurationHistogram h1; +        h1.AddTime(TDuration::MicroSeconds(1)); +        UNIT_ASSERT_VALUES_EQUAL(1u, h1.Times.front()); + +        TDurationHistogram h2; +        h1.AddTime(TDuration::Hours(1)); +        UNIT_ASSERT_VALUES_EQUAL(1u, h1.Times.back()); +    } + +    Y_UNIT_TEST(LabelFor) { +        for (unsigned i = 0; i < TDurationHistogram::Buckets; ++i) { +            TDurationHistogram::LabelBefore(i); +            //Cerr << TDurationHistogram::LabelBefore(i) << "\n"; +        } +    } +}  | 
