aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/sliding_window/sliding_window_ut.cpp
diff options
context:
space:
mode:
authorVasily Gerasimov <UgnineSirdis@gmail.com>2022-02-10 16:49:10 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:10 +0300
commit1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/sliding_window/sliding_window_ut.cpp
parent6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff)
downloadydb-1eb755fbca92172a6aec2f57371b2b3a19dfab43.tar.gz
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/sliding_window/sliding_window_ut.cpp')
-rw-r--r--library/cpp/sliding_window/sliding_window_ut.cpp106
1 files changed, 53 insertions, 53 deletions
diff --git a/library/cpp/sliding_window/sliding_window_ut.cpp b/library/cpp/sliding_window/sliding_window_ut.cpp
index 22814fadeb..1e7343a8d3 100644
--- a/library/cpp/sliding_window/sliding_window_ut.cpp
+++ b/library/cpp/sliding_window/sliding_window_ut.cpp
@@ -2,131 +2,131 @@
#include <library/cpp/testing/unittest/registar.h>
-using namespace NSlidingWindow;
+using namespace NSlidingWindow;
Y_UNIT_TEST_SUITE(TSlidingWindowTest) {
Y_UNIT_TEST(TestSlidingWindowMax) {
- TSlidingWindow<TMaxOperation<unsigned>> w(TDuration::Minutes(5), 5);
+ TSlidingWindow<TMaxOperation<unsigned>> w(TDuration::Minutes(5), 5);
TInstant start = TInstant::MicroSeconds(TDuration::Hours(1).MicroSeconds());
- TInstant now = start;
+ TInstant now = start;
w.Update(5, start); // ~ ~ ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1) + TDuration::Seconds(1);
+ now += TDuration::Minutes(1) + TDuration::Seconds(1);
w.Update(5, now); // 5 ~ ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(3, now); // 5 3 ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(3);
+ now += TDuration::Minutes(3);
w.Update(2, now); // 5 3 ~ ~ 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(2, now); // 2 3 ~ ~ 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 3); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(2, now); // 2 2 ~ ~ 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 2); // ^
- now += TDuration::Minutes(5);
+ now += TDuration::Minutes(5);
w.Update(1, now); // ~ 1 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 1); // ^
- // update current bucket
+ // update current bucket
w.Update(2, now); // ~ 2 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 2); // ^
-
+
w.Update(1, now + TDuration::Seconds(30)); // ~ 2 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 2); // ^
-
- // test idle
- now += TDuration::Minutes(1);
+
+ // test idle
+ now += TDuration::Minutes(1);
w.Update(now); // ~ 2 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 2); // ^
-
+
now += TDuration::Minutes(5); // ~ ~ ~ ~ ~
- UNIT_ASSERT_VALUES_EQUAL(w.Update(now), 0);
+ UNIT_ASSERT_VALUES_EQUAL(w.Update(now), 0);
}
Y_UNIT_TEST(TestSlidingWindowMin) {
- TSlidingWindow<TMinOperation<unsigned>> w(TDuration::Minutes(5), 5);
+ TSlidingWindow<TMinOperation<unsigned>> w(TDuration::Minutes(5), 5);
TInstant start = TInstant::MicroSeconds(TDuration::Hours(1).MicroSeconds());
- TInstant now = start;
+ TInstant now = start;
w.Update(5, start); // ~ ~ ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1) + TDuration::Seconds(1);
+ now += TDuration::Minutes(1) + TDuration::Seconds(1);
w.Update(5, now); // 5 ~ ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(7, now); // 5 7 ~ ~ 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(3);
+ now += TDuration::Minutes(3);
w.Update(8, now); // 5 7 ~ ~ 8
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(8, now); // 8 7 ~ ~ 8
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 7); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(8, now); // 8 8 ~ ~ 8
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 8); // ^
- now += TDuration::Minutes(5);
+ now += TDuration::Minutes(5);
w.Update(6, now); // ~ 6 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 6); // ^
- // update current bucket
+ // update current bucket
w.Update(5, now); // ~ 5 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
-
+
w.Update(6, now + TDuration::Seconds(30)); // ~ 5 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
-
- // test idle
- now += TDuration::Minutes(1);
+
+ // test idle
+ now += TDuration::Minutes(1);
w.Update(now); // ~ 5 ~ ~ ~
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
-
+
now += TDuration::Minutes(5); // ~ ~ ~ ~ ~
- UNIT_ASSERT_VALUES_EQUAL(w.Update(now), std::numeric_limits<unsigned>::max());
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(w.Update(now), std::numeric_limits<unsigned>::max());
+ }
+
Y_UNIT_TEST(TestSlidingWindowSum) {
- TSlidingWindow<TSumOperation<unsigned>> w(TDuration::Minutes(5), 5);
- UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 0); // current sum
-
+ TSlidingWindow<TSumOperation<unsigned>> w(TDuration::Minutes(5), 5);
+ UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 0); // current sum
+
TInstant start = TInstant::MicroSeconds(TDuration::Hours(1).MicroSeconds());
- TInstant now = start;
+ TInstant now = start;
w.Update(5, start); // 0 0 0 0 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 5); // ^
- now += TDuration::Minutes(1) + TDuration::Seconds(1);
+ now += TDuration::Minutes(1) + TDuration::Seconds(1);
w.Update(5, now); // 5 0 0 0 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 10); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(3, now); // 5 3 0 0 5
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 13); // ^
- now += TDuration::Minutes(3);
+ now += TDuration::Minutes(3);
w.Update(2, now); // 5 3 0 0 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 10); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(2, now); // 2 3 0 0 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 7); // ^
- now += TDuration::Minutes(1);
+ now += TDuration::Minutes(1);
w.Update(2, now); // 2 2 0 0 2
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 6); // ^
- now += TDuration::Minutes(5);
+ now += TDuration::Minutes(5);
w.Update(1, now); // 0 1 0 0 0
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 1); // ^
-
- // update current bucket
+
+ // update current bucket
w.Update(2, now); // 0 3 0 0 0
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 3); // ^
-
+
w.Update(1, now + TDuration::Seconds(30)); // 0 4 0 0 0
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 4); // ^
-
- // test idle
- now += TDuration::Minutes(1);
+
+ // test idle
+ now += TDuration::Minutes(1);
w.Update(now); // 0 4 0 0 0
UNIT_ASSERT_VALUES_EQUAL(w.GetValue(), 4); // ^
-
+
now += TDuration::Minutes(5); // 0 0 0 0 0
- UNIT_ASSERT_VALUES_EQUAL(w.Update(now), 0);
- }
-}
+ UNIT_ASSERT_VALUES_EQUAL(w.Update(now), 0);
+ }
+}