duration_histogram_ut.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "duration_histogram.h"
  3. Y_UNIT_TEST_SUITE(TDurationHistogramTest) {
  4. Y_UNIT_TEST(BucketFor) {
  5. UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(0)));
  6. UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(1)));
  7. UNIT_ASSERT_VALUES_EQUAL(0u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(900)));
  8. UNIT_ASSERT_VALUES_EQUAL(1u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(1500)));
  9. UNIT_ASSERT_VALUES_EQUAL(2u, TDurationHistogram::BucketFor(TDuration::MicroSeconds(2500)));
  10. unsigned sb = TDurationHistogram::SecondBoundary;
  11. UNIT_ASSERT_VALUES_EQUAL(sb - 1, TDurationHistogram::BucketFor(TDuration::MilliSeconds(999)));
  12. UNIT_ASSERT_VALUES_EQUAL(sb, TDurationHistogram::BucketFor(TDuration::MilliSeconds(1000)));
  13. UNIT_ASSERT_VALUES_EQUAL(sb, TDurationHistogram::BucketFor(TDuration::MilliSeconds(1001)));
  14. UNIT_ASSERT_VALUES_EQUAL(TDurationHistogram::Buckets - 1, TDurationHistogram::BucketFor(TDuration::Hours(1)));
  15. }
  16. Y_UNIT_TEST(Simple) {
  17. TDurationHistogram h1;
  18. h1.AddTime(TDuration::MicroSeconds(1));
  19. UNIT_ASSERT_VALUES_EQUAL(1u, h1.Times.front());
  20. TDurationHistogram h2;
  21. h1.AddTime(TDuration::Hours(1));
  22. UNIT_ASSERT_VALUES_EQUAL(1u, h1.Times.back());
  23. }
  24. Y_UNIT_TEST(LabelFor) {
  25. for (unsigned i = 0; i < TDurationHistogram::Buckets; ++i) {
  26. TDurationHistogram::LabelBefore(i);
  27. //Cerr << TDurationHistogram::LabelBefore(i) << "\n";
  28. }
  29. }
  30. }