X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FFBVectorTest.cpp;h=33a164a004efe0379dd05ef1c78f570c7556c8c4;hb=86b83461fc47b591b9e873e36ceabe4efa03e11f;hp=919063e81d379c42fe0e6147b2dfbbe111ae3d4f;hpb=ce64f0f685111ac24c7a321ea56d0c3524621df1;p=folly.git diff --git a/folly/test/FBVectorTest.cpp b/folly/test/FBVectorTest.cpp index 919063e8..33a164a0 100644 --- a/folly/test/FBVectorTest.cpp +++ b/folly/test/FBVectorTest.cpp @@ -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. @@ -17,13 +17,12 @@ // // Author: andrei.alexandrescu@fb.com +#include #include #include #include #include -#include - #include #include #include @@ -33,11 +32,11 @@ using namespace std; using namespace folly; +namespace { + auto static const seed = randomNumberSeed(); typedef boost::mt19937 RandomT; static RandomT rng(seed); -static const size_t maxString = 100; -static const bool avoidAliasing = true; template Integral2 random(Integral1 low, Integral2 up) { @@ -55,31 +54,17 @@ void randomString(String* toFill, unsigned int maxSize = 1000) { } template -void Num2String(String& str, Integral n) { +void Num2String(String& str, Integral /* n */) { str.resize(10, '\0'); sprintf(&str[0], "%ul", 10); str.resize(strlen(str.c_str())); } -std::list RandomList(unsigned int maxSize) { - std::list lst(random(0u, maxSize)); - std::list::iterator i = lst.begin(); - for (; i != lst.end(); ++i) { - *i = random('a', 'z'); - } - return lst; -} - template T randomObject(); template<> int randomObject() { return random(0, 1024); } - -template<> folly::fbstring randomObject() { - folly::fbstring result; - randomString(&result); - return result; } //////////////////////////////////////////////////////////////////////////////// @@ -274,8 +259,12 @@ TEST(FBVector, vector_of_maps) { EXPECT_EQ(1, v[1].size()); } -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - google::ParseCommandLineFlags(&argc, &argv, true); - return RUN_ALL_TESTS(); +TEST(FBVector, shrink_to_fit_after_clear) { + fbvector fb1; + fb1.push_back(42); + fb1.push_back(1337); + fb1.clear(); + fb1.shrink_to_fit(); + EXPECT_EQ(fb1.size(), 0); + EXPECT_EQ(fb1.capacity(), 0); }