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

Unified 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: clang npos Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/unique_vector_unittest.cc
diff --git a/tools/gn/unique_vector_unittest.cc b/tools/gn/unique_vector_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..40d6d9350324a7e94e855ac3d38cf21a979fae7c
--- /dev/null
+++ b/tools/gn/unique_vector_unittest.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/unique_vector.h"
+
+TEST(UniqueVector, PushBack) {
+ UniqueVector<int> foo;
+ EXPECT_TRUE(foo.push_back(1));
+ EXPECT_FALSE(foo.push_back(1));
+ EXPECT_TRUE(foo.push_back(2));
+ EXPECT_TRUE(foo.push_back(0));
+ EXPECT_FALSE(foo.push_back(2));
+ EXPECT_FALSE(foo.push_back(1));
+
+ EXPECT_EQ(3u, foo.size());
+ EXPECT_EQ(1, foo[0]);
+ EXPECT_EQ(2, foo[1]);
+ EXPECT_EQ(0, foo[2]);
+
+ // Verify those results with IndexOf as well.
+ EXPECT_EQ(0u, foo.IndexOf(1));
+ EXPECT_EQ(1u, foo.IndexOf(2));
+ EXPECT_EQ(2u, foo.IndexOf(0));
+ EXPECT_EQ(UniqueVector<int>::npos, foo.IndexOf(99));
+}
+
+TEST(UniqueVector, PushBackViaSwap) {
+ UniqueVector<std::string> vect;
+ std::string a("a");
+ EXPECT_TRUE(vect.PushBackViaSwap(&a));
+ EXPECT_EQ("", a);
+
+ a = "a";
+ EXPECT_FALSE(vect.PushBackViaSwap(&a));
+ EXPECT_EQ("a", a);
+
+ EXPECT_EQ(0u, vect.IndexOf("a"));
+}

Powered by Google App Engine
This is Rietveld 408576698