Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: tools/gn/unique_vector_unittest.cc

Issue 26537002: Add a UniqueVector class to GN (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: REview comments, remove npos Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/unique_vector.h ('k') | tools/gn/value_extractors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include <algorithm>
6
7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/unique_vector.h"
10
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));
19
20 EXPECT_EQ(3u, foo.size());
21 EXPECT_EQ(1, foo[0]);
22 EXPECT_EQ(2, foo[1]);
23 EXPECT_EQ(0, foo[2]);
24
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));
30 }
31
32 TEST(UniqueVector, PushBackViaSwap) {
33 UniqueVector<std::string> vect;
34 std::string a("a");
35 EXPECT_TRUE(vect.PushBackViaSwap(&a));
36 EXPECT_EQ("", a);
37
38 a = "a";
39 EXPECT_FALSE(vect.PushBackViaSwap(&a));
40 EXPECT_EQ("a", a);
41
42 EXPECT_EQ(0u, vect.IndexOf("a"));
43 }
OLDNEW
« no previous file with comments | « tools/gn/unique_vector.h ('k') | tools/gn/value_extractors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698