FBString: remove unnecessary 7-byte padding in large strings
[folly.git] / folly / test / sorted_vector_test.cpp
index 2b75a5202866d7e01fce4966a1cb48220141b703..2c7160ea4e426ec049319779dd74cac9fd3815c6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 #include <folly/sorted_vector_types.h>
-#include <gtest/gtest.h>
+
 #include <list>
+#include <memory>
+
+#include <folly/portability/GTest.h>
 
 using folly::sorted_vector_set;
 using folly::sorted_vector_map;
 
 namespace {
 
-template<class T>
-struct less_invert : std::binary_function<T,T,bool> {
+template <class T>
+struct less_invert {
   bool operator()(const T& a, const T& b) const {
     return b < a;
   }
@@ -149,10 +152,12 @@ TEST(SortedVectorTypes, SimpleMapTest) {
   m[32] = 100.0;
   check_invariant(m);
   EXPECT_TRUE(m.count(32) == 1);
+  EXPECT_DOUBLE_EQ(100.0, m.at(32));
   EXPECT_FALSE(m.find(32) == m.end());
   m.erase(32);
   EXPECT_TRUE(m.find(32) == m.end());
   check_invariant(m);
+  EXPECT_THROW(m.at(32), std::out_of_range);
 
   sorted_vector_map<int,float> m2 = m;
   EXPECT_TRUE(m2 == m);
@@ -278,7 +283,7 @@ TEST(SortedVectorTypes, GrowthPolicy) {
 
   std::list<CountCopyCtor> v;
   for (int i = 0; i < 20; ++i) {
-    v.push_back(CountCopyCtor(20 + i));
+    v.emplace_back(20 + i);
   }
   a.insert(v.begin(), v.end());
   check_invariant(a);
@@ -300,6 +305,7 @@ TEST(SortedVectorTest, EmptyTest) {
   sorted_vector_map<int,int> emptyMap;
   EXPECT_TRUE(emptyMap.lower_bound(10) == emptyMap.end());
   EXPECT_TRUE(emptyMap.find(10) == emptyMap.end());
+  EXPECT_THROW(emptyMap.at(10), std::out_of_range);
 }
 
 TEST(SortedVectorTest, MoveTest) {
@@ -333,3 +339,11 @@ TEST(SortedVectorTest, ShrinkTest) {
   // vector::shrink_to_fit respects the caller.
   EXPECT_EQ(s.capacity(), s.size());
 }
+
+TEST(SortedVectorTypes, EraseTest) {
+  sorted_vector_set<int> s1;
+  s1.insert(1);
+  sorted_vector_set<int> s2(s1);
+  EXPECT_EQ(0, s1.erase(0));
+  EXPECT_EQ(s2, s1);
+}