test_assign.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 <list>
16 #include <memory>
17 #include <vector>
18 
19 #include <gtest/gtest.h>
20 
22 
23 #include <range/v3/action/drop.hpp>
24 #include <range/v3/action/remove.hpp>
25 #include <range/v3/algorithm/equal.hpp>
26 #include <range/v3/view/indirect.hpp>
27 #include <range/v3/view/move.hpp>
28 #include <range/v3/view/reverse.hpp>
29 #include <range/v3/view/transform.hpp>
30 
31 namespace {
32 
33 TEST(AssignAction, ViewToAction) {
34  auto input = std::vector{1, 2, 3};
35  input |= ranges::views::reverse | beluga::actions::assign;
36  ASSERT_TRUE(ranges::equal(input, std::vector{3, 2, 1}));
37 }
38 
39 TEST(AssignAction, MoveOnlyRange) {
40  auto input = std::vector<std::unique_ptr<int>>{};
41  input.emplace_back(std::make_unique<int>(1));
42  input.emplace_back(std::make_unique<int>(2));
43  input.emplace_back(std::make_unique<int>(3));
44  input |= ranges::views::reverse | ranges::views::move | beluga::actions::assign;
45  ASSERT_TRUE(ranges::equal(input | ranges::views::indirect, std::vector{3, 2, 1}));
46 }
47 
48 TEST(AssignAction, ViewToActionComposition) {
49  auto reverse_and_assign = ranges::views::reverse | beluga::actions::assign;
50  auto input = std::vector{1, 2, 3};
51  input |= reverse_and_assign;
52  ASSERT_TRUE(ranges::equal(input, std::vector{3, 2, 1}));
53 }
54 
55 TEST(AssignAction, ViewToActionCall) {
56  auto input = std::vector{1, 2, 3};
57  beluga::actions::assign(input, ranges::views::reverse);
58  ASSERT_TRUE(ranges::equal(input, std::vector{3, 2, 1}));
59 }
60 
61 TEST(AssignAction, ActionComposition) {
62  auto input = std::vector{1, 2, 3};
63  input |= ranges::actions::drop(1) | beluga::actions::assign;
64  ASSERT_TRUE(ranges::equal(input, std::vector{2, 3}));
65 }
66 
67 TEST(AssignAction, ActionViewComposition) {
68  auto input = std::vector{1, 2, 3};
69  input |= ranges::actions::drop(1) | ranges::views::reverse | beluga::actions::assign;
70  ASSERT_TRUE(ranges::equal(input, std::vector{3, 2}));
71 }
72 
73 TEST(AssignAction, ActionViewActionComposition) {
74  auto input = std::vector{1, 2, 3};
75  input |= ranges::actions::drop(1) | //
76  ranges::views::reverse | //
78  ranges::actions::drop(1) | //
79  ranges::views::transform([](auto value) { return value + 10; }) | //
81  ASSERT_TRUE(ranges::equal(input, std::vector{12}));
82 }
83 
84 TEST(AssignAction, List) {
85  auto input = std::list{1, 2, 3};
86  input |= ranges::actions::remove(2) | ranges::views::reverse | beluga::actions::assign;
87  ASSERT_TRUE(ranges::equal(input, std::list{3, 1}));
88 }
89 
90 } // namespace
beluga::actions::assign
constexpr detail::assign_fn assign
Definition: assign.hpp:99
assign.hpp
Implementation of the assign range adaptor object.
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


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