test_every_n.cpp
Go to the documentation of this file.
1 // Copyright 2024 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gtest/gtest.h>
16 
18 
19 namespace {
20 
21 TEST(EveryNPolicy, TriggerOnNthCall) {
22  auto policy = beluga::policies::every_n(3); // Trigger every 3rd call
23  ASSERT_FALSE(policy());
24  ASSERT_FALSE(policy());
25  ASSERT_TRUE(policy());
26 }
27 
28 TEST(EveryNPolicy, NoTriggerBeforeN) {
29  auto policy = beluga::policies::every_n(4); // Trigger every 4th call
30  ASSERT_FALSE(policy());
31  ASSERT_FALSE(policy());
32  ASSERT_FALSE(policy());
33 }
34 
35 TEST(EveryNPolicy, TriggerOnMultipleN) {
36  auto policy = beluga::policies::every_n(2); // Trigger every 2nd call
37  ASSERT_FALSE(policy());
38  ASSERT_TRUE(policy());
39  ASSERT_FALSE(policy());
40  ASSERT_TRUE(policy());
41 }
42 
43 } // namespace
beluga::policies::every_n
constexpr detail::every_n_fn every_n
Policy that triggers an action every N calls.
Definition: every_n.hpp:70
every_n.hpp
Defines a policy for triggering an action every N calls.
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53