1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/unique_vector.h"
11 TEST(UniqueVector
, PushBack
) {
12 UniqueVector
<int> foo
;
13 EXPECT_TRUE(foo
.push_back(1));
14 EXPECT_FALSE(foo
.push_back(1));
15 EXPECT_TRUE(foo
.push_back(2));
16 EXPECT_TRUE(foo
.push_back(0));
17 EXPECT_FALSE(foo
.push_back(2));
18 EXPECT_FALSE(foo
.push_back(1));
20 EXPECT_EQ(3u, foo
.size());
25 // Verify those results with IndexOf as well.
26 EXPECT_EQ(0u, foo
.IndexOf(1));
27 EXPECT_EQ(1u, foo
.IndexOf(2));
28 EXPECT_EQ(2u, foo
.IndexOf(0));
29 EXPECT_EQ(static_cast<size_t>(-1), foo
.IndexOf(99));
32 TEST(UniqueVector
, PushBackViaSwap
) {
33 UniqueVector
<std::string
> vect
;
35 EXPECT_TRUE(vect
.PushBackViaSwap(&a
));
39 EXPECT_FALSE(vect
.PushBackViaSwap(&a
));
42 EXPECT_EQ(0u, vect
.IndexOf("a"));