optional_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "gtest/gtest.h"
20 
21 namespace cartographer {
22 namespace common {
23 namespace {
24 
25 TEST(OptionalTest, CreateDisengagedObject) {
26  const optional<int> o;
27  EXPECT_FALSE(o.has_value());
28  const optional<float> x;
29  EXPECT_FALSE(x.has_value());
30 }
31 
32 TEST(OptionalTest, CreateWithValue) {
33  const optional<int> a(5);
34  EXPECT_TRUE(a.has_value());
35  EXPECT_EQ(5, a.value());
36 }
37 
38 TEST(OptionalTest, CreateFromOtherOptional) {
39  const optional<int> a(5);
40  const optional<int> b = a;
41  EXPECT_TRUE(a.has_value());
42  EXPECT_TRUE(b.has_value());
43  EXPECT_EQ(5, a.value());
44  EXPECT_EQ(5, b.value());
45 }
46 
47 TEST(OptionalTest, AssignmentOperator) {
48  optional<int> a(5);
49  optional<int> b(4);
50  optional<int> c;
51  a = b;
52  EXPECT_TRUE(a.has_value());
53  EXPECT_EQ(4, a.value());
54  a = c;
55  EXPECT_FALSE(a.has_value());
56  a = 3;
57  EXPECT_TRUE(a.has_value());
58  EXPECT_EQ(3, a.value());
59 }
60 
61 } // namespace
62 } // namespace common
63 } // namespace cartographer
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58