1 // Copyright 2013 Google Inc. All Rights Reserved.
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 
16 // Author: ericv@google.com (Eric Veach)
17 
18 #include "s2/s2point_vector_shape.h"
19 
20 #include <vector>
21 
22 #include <gtest/gtest.h>
23 #include "s2/s2testing.h"
24 
TEST(S2PointVectorShape,Empty)25 TEST(S2PointVectorShape, Empty) {
26   std::vector<S2Point> points;
27   S2PointVectorShape shape(std::move(points));
28   EXPECT_EQ(0, shape.num_edges());
29   EXPECT_EQ(0, shape.num_chains());
30   EXPECT_EQ(0, shape.dimension());
31   EXPECT_TRUE(shape.is_empty());
32   EXPECT_FALSE(shape.is_full());
33   EXPECT_FALSE(shape.GetReferencePoint().contained);
34 }
35 
TEST(S2PointVectorShape,ConstructionAndAccess)36 TEST(S2PointVectorShape, ConstructionAndAccess) {
37   std::vector<S2Point> points;
38   S2Testing::rnd.Reset(FLAGS_s2_random_seed);
39   const int kNumPoints = 100;
40   for (int i = 0; i < kNumPoints; ++i) {
41     points.push_back(S2Testing::RandomPoint());
42   }
43   S2PointVectorShape shape(std::move(points));
44 
45   EXPECT_EQ(kNumPoints, shape.num_edges());
46   EXPECT_EQ(kNumPoints, shape.num_chains());
47   EXPECT_EQ(0, shape.dimension());
48   EXPECT_FALSE(shape.is_empty());
49   EXPECT_FALSE(shape.is_full());
50   S2Testing::rnd.Reset(FLAGS_s2_random_seed);
51   for (int i = 0; i < kNumPoints; ++i) {
52     EXPECT_EQ(i, shape.chain(i).start);
53     EXPECT_EQ(1, shape.chain(i).length);
54     auto edge = shape.edge(i);
55     S2Point pt = S2Testing::RandomPoint();
56     EXPECT_EQ(pt, edge.v0);
57     EXPECT_EQ(pt, edge.v1);
58   }
59 }
60