2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
20 /* Author : Ashwin Sridharan
24 #define CATCH_CONFIG_MAIN
25 #include <catch2/catch.hpp>
27 #include <sliding_window.hpp>
29 TEST_CASE("Unit tests for sliding window", "sliding window"){
31 SECTION("Invalid window"){
32 REQUIRE_THROWS(sliding_window(-1));
33 REQUIRE_THROWS(sliding_window(MAX_WINDOW_SIZE + 1));
38 sliding_window my_window(window_size);
39 REQUIRE(my_window.net_events == 0);
42 for(int i = 0; i < num_events; i++){
43 my_window.update_window(1);
46 REQUIRE(my_window.net_events == num_events);
48 // test window shift after delay more than window size
49 std::this_thread::sleep_for(std::chrono::seconds(window_size + 3));
51 my_window.update_window(1);
52 REQUIRE(my_window.net_events == 1);
54 std::this_thread::sleep_for(std::chrono::seconds(window_size + 3));
58 for(int i = 0; i < window_size; i++){
59 my_window.update_window(1);
60 std::this_thread::sleep_for(std::chrono::seconds(1));
63 REQUIRE(my_window.net_events == window_size);
65 ss << "[Events] = " << my_window.net_events << std::endl;
66 REQUIRE_THAT(my_window.display_window(), Catch::Matchers::EndsWith(ss.str()));
74 sliding_window my_window(window_size);
75 REQUIRE(my_window.net_events == 0);
78 for(int i = 0; i < num_events; i++){
79 my_window.update_window(1);
82 REQUIRE(my_window.net_events == num_events);
84 int new_window_size = 2;
85 res = my_window.resize_window(2);
87 REQUIRE(my_window.net_events == 0);
89 my_window.update_window(100);
90 REQUIRE(my_window.net_events == 100);
92 std::this_thread::sleep_for(std::chrono::seconds(new_window_size + 1));
93 my_window.update_window(1);
94 REQUIRE(my_window.net_events == 1);
96 res = my_window.resize_window(-1);
97 REQUIRE(res == false);
99 res = my_window.resize_window(MAX_WINDOW_SIZE + 1);
100 REQUIRE(res == false);
104 REQUIRE(my_window.net_events == 0);