OR-Tools  9.6
simple_graph_test.cc
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
15 
16 #include <sstream>
17 #include <string>
18 
19 #include "absl/hash/hash_testing.h"
20 #include "gtest/gtest.h"
21 
22 namespace operations_research {
23 namespace {
24 TEST(SimpleGraphTest, EdgeHashing) {
25  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly({
26  Edge(0, 0),
27  Edge(1, 2),
28  Edge(2, 1),
29  }));
30 }
31 
32 TEST(SimpleGraphTest, EdgeEquality) {
33  EXPECT_EQ(Edge(0, 0), Edge(0, 0));
34  EXPECT_NE(Edge(0, 0), Edge(1, 2));
35  EXPECT_EQ(Edge(2, 1), Edge(1, 2)); // Undirected edge.
36 }
37 
38 TEST(SimpleGraphTest, ArcHashing) {
39  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly({
40  Arc(0, 0),
41  Arc(1, 2),
42  Arc(2, 1),
43  }));
44 }
45 
46 TEST(SimpleGraphTest, ArcEquality) {
47  EXPECT_EQ(Arc(0, 0), Arc(0, 0));
48  EXPECT_NE(Arc(0, 0), Arc(1, 2));
49  EXPECT_NE(Arc(2, 1), Arc(1, 2)); // Directed edge.
50 }
51 
52 TEST(Coordinates2Test, Int) {
53  EXPECT_EQ(Coordinates2<int>(0, 0), Coordinates2<int>(0, 0));
54  EXPECT_NE(Coordinates2<int>(0, 0), Coordinates2<int>(1, 2));
55 
56  std::stringstream generated;
57  generated << Coordinates2<int>(0, 1);
58  EXPECT_EQ(generated.str(), "{x = 0, y = 1}");
59 
60  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
61  {Coordinates2<int>(), Coordinates2<int>(0, 0), Coordinates2<int>(1, 2)}));
62 }
63 
64 TEST(Coordinates2Test, Double) {
65  EXPECT_EQ(Coordinates2<double>(0, 0), Coordinates2<double>(0, 0));
66  EXPECT_NE(Coordinates2<double>(0, 0), Coordinates2<double>(1, 2));
67 
68  std::stringstream generated;
69  generated << Coordinates2<double>(0.0, 1.0);
70  EXPECT_EQ(generated.str(), "{x = 0, y = 1}");
71 
72  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
73  {Coordinates2<double>(), Coordinates2<double>(0, 0),
74  Coordinates2<double>(1, 2)}));
75 }
76 
77 TEST(Coordinates3Test, Int) {
78  EXPECT_EQ(Coordinates3<int>(0, 0, 0), Coordinates3<int>(0, 0, 0));
79  EXPECT_NE(Coordinates3<int>(0, 0, 0), Coordinates3<int>(1, 2, 3));
80 
81  std::stringstream generated;
82  generated << Coordinates3<int>(0, 1, 2);
83  EXPECT_EQ(generated.str(), "{x = 0, y = 1, z = 2}");
84 
85  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
86  {Coordinates3<int>(), Coordinates3<int>(0, 0, 0),
87  Coordinates3<int>(1, 2, 3)}));
88 }
89 
90 TEST(Coordinates3Test, Double) {
91  EXPECT_EQ(Coordinates3<double>(0, 0, 0), Coordinates3<double>(0, 0, 0));
92  EXPECT_NE(Coordinates3<double>(0, 0, 0), Coordinates3<double>(1, 2, 3));
93 
94  std::stringstream generated;
95  generated << Coordinates3<double>(0.0, 1.0, 2.0);
96  EXPECT_EQ(generated.str(), "{x = 0, y = 1, z = 2}");
97 
98  EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(
99  {Coordinates3<double>(), Coordinates3<double>(0.0, 0.0, 0.0),
100  Coordinates3<double>(1.0, 2.0, 3.0)}));
101 }
102 } // namespace
103 } // namespace operations_research
Collection of objects used to extend the Constraint Solver library.
TEST(LinearAssignmentTest, NullMatrix)