test_take_evenly.cpp
Go to the documentation of this file.
1 // Copyright 2023 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 <gmock/gmock.h>
16 #include <gtest/gtest.h>
17 
18 #include <vector>
19 
20 #include <range/v3/range/conversion.hpp>
21 #include <range/v3/view/iota.hpp>
22 
24 
25 namespace {
26 
27 TEST(TakeEvenlyView, NoElementsTakeZero) {
28  const auto input = std::vector<int>{};
29  const auto output = input | beluga::views::take_evenly(0) | ranges::to<std::vector>;
30  ASSERT_EQ(output.size(), 0);
31 }
32 
33 TEST(TakeEvenlyView, NoElements) {
34  const auto input = std::vector<int>{};
35  const auto output = input | beluga::views::take_evenly(1) | ranges::to<std::vector>;
36  ASSERT_EQ(output.size(), 0);
37 }
38 
39 TEST(TakeEvenlyView, TakeZero) {
40  const auto input = std::vector<int>{1, 2, 3, 4};
41  const auto output = input | beluga::views::take_evenly(0) | ranges::to<std::vector>;
42  ASSERT_EQ(output.size(), 0);
43 }
44 
45 TEST(TakeEvenlyView, TakeOne) {
46  const auto input = std::vector<int>{1, 2, 3, 4};
47  const auto output = input | beluga::views::take_evenly(1) | ranges::to<std::vector>;
48  ASSERT_THAT(output, testing::ElementsAre(1));
49 }
50 
51 TEST(TakeEvenlyView, TakeAll) {
52  const auto input = std::vector<int>{1, 2, 3, 4};
53  const auto output = input | beluga::views::take_evenly(10) | ranges::to<std::vector>;
54  ASSERT_THAT(output, testing::ElementsAre(1, 2, 3, 4));
55 }
56 
57 TEST(TakeEvenlyView, TakeTwoFromFour) {
58  const auto input = std::vector<int>{1, 2, 3, 4};
59  const auto output = input | beluga::views::take_evenly(2) | ranges::to<std::vector>;
60  ASSERT_THAT(output, testing::ElementsAre(1, 4));
61 }
62 
63 TEST(TakeEvenlyView, TakeThreeFromFive) {
64  const auto input = std::vector<int>{1, 2, 3, 4, 5};
65  const auto output = input | beluga::views::take_evenly(3) | ranges::to<std::vector>;
66  ASSERT_THAT(output, testing::ElementsAre(1, 3, 5));
67 }
68 
69 TEST(TakeEvenlyView, TakeThreeFromSix) {
70  const auto input = std::vector<int>{1, 2, 3, 4, 5, 6};
71  const auto output = input | beluga::views::take_evenly(3) | ranges::to<std::vector>;
72  ASSERT_THAT(output, testing::ElementsAre(1, 4, 6));
73 }
74 
75 TEST(TakeEvenlyView, TakeThreeFromNine) {
76  const auto input = std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9};
77  const auto output = input | beluga::views::take_evenly(3) | ranges::to<std::vector>;
78  ASSERT_THAT(output, testing::ElementsAre(1, 5, 9));
79 }
80 
81 TEST(TakeEvenlyView, TakeThreeFromFour) {
82  const auto input = std::vector<int>{1, 2, 3, 4};
83  const auto output = input | beluga::views::take_evenly(3) | ranges::to<std::vector>;
84  ASSERT_THAT(output, testing::ElementsAre(1, 3, 4));
85 }
86 
87 TEST(TakeEvenlyView, TakeSixFromTen) {
88  const auto input = std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
89  const auto output = input | beluga::views::take_evenly(6) | ranges::to<std::vector>;
90  ASSERT_THAT(output, testing::ElementsAre(1, 3, 5, 7, 9, 10));
91 }
92 
93 TEST(TakeEvenlyView, TakeFromGenerator) {
94  const auto output = ranges::views::iota(1, 6) | beluga::views::take_evenly(3) | ranges::to<std::vector>;
95  ASSERT_THAT(output, testing::ElementsAre(1, 3, 5));
96 }
97 
98 } // namespace
take_evenly.hpp
Implementation of a take_evenly range adaptor object.
beluga::views::take_evenly
constexpr detail::take_evenly_fn take_evenly
Definition: take_evenly.hpp:102
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


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