Commit 69cc5b59 authored by Andrew Gallagher's avatar Andrew Gallagher Committed by Facebook Github Bot

folly/test: move some of `FBVectorTestUtil.h` into `FBVectorTestUtil.cpp`

Reviewed By: yfeldblum

Differential Revision: D13279970

fbshipit-source-id: 78b325029878c1ff5fb2e1c59d5765121818b55b
parent af6cff95
...@@ -307,6 +307,7 @@ if (BUILD_TESTS) ...@@ -307,6 +307,7 @@ if (BUILD_TESTS)
add_library(folly_test_support add_library(folly_test_support
${FOLLY_DIR}/test/common/TestMain.cpp ${FOLLY_DIR}/test/common/TestMain.cpp
${FOLLY_DIR}/test/FBVectorTestUtil.cpp
${FOLLY_DIR}/test/DeterministicSchedule.cpp ${FOLLY_DIR}/test/DeterministicSchedule.cpp
${FOLLY_DIR}/test/DeterministicSchedule.h ${FOLLY_DIR}/test/DeterministicSchedule.h
${FOLLY_DIR}/test/SingletonTestStructs.cpp ${FOLLY_DIR}/test/SingletonTestStructs.cpp
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/test/FBVectorTestUtil.h>
#include <list>
#include <string>
#include <boost/random/mersenne_twister.hpp>
#include <folly/FBString.h>
#include <folly/Random.h>
namespace folly {
namespace test {
namespace detail {
RandomT rng(seed);
std::list<char> RandomList(unsigned int maxSize) {
std::list<char> lst(random(0u, maxSize));
std::list<char>::iterator i = lst.begin();
for (; i != lst.end(); ++i) {
*i = random('a', 'z');
}
return lst;
}
template <>
int randomObject<int>() {
return random(0, 1024);
}
template <>
std::string randomObject<std::string>() {
std::string result;
randomString(&result);
return result;
}
template <>
folly::fbstring randomObject<folly::fbstring>() {
folly::fbstring result;
randomString(&result);
return result;
}
} // namespace detail
} // namespace test
} // namespace folly
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
// //
// Author: andrei.alexandrescu@fb.com // Author: andrei.alexandrescu@fb.com
#include <list>
#include <boost/random/mersenne_twister.hpp> #include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <folly/Benchmark.h> #include <folly/Benchmark.h>
#include <folly/FBString.h> #include <folly/FBString.h>
...@@ -30,7 +33,7 @@ namespace detail { ...@@ -30,7 +33,7 @@ namespace detail {
auto static const seed = randomNumberSeed(); auto static const seed = randomNumberSeed();
typedef boost::random::mt19937 RandomT; typedef boost::random::mt19937 RandomT;
static RandomT rng(seed); extern RandomT rng;
template <class Integral1, class Integral2> template <class Integral1, class Integral2>
Integral2 random(Integral1 low, Integral2 up) { Integral2 random(Integral1 low, Integral2 up) {
...@@ -54,36 +57,19 @@ void Num2String(String& str, Integral /* n */) { ...@@ -54,36 +57,19 @@ void Num2String(String& str, Integral /* n */) {
str.resize(strlen(str.c_str())); str.resize(strlen(str.c_str()));
} }
std::list<char> RandomList(unsigned int maxSize) { std::list<char> RandomList(unsigned int maxSize);
std::list<char> lst(random(0u, maxSize));
std::list<char>::iterator i = lst.begin();
for (; i != lst.end(); ++i) {
*i = random('a', 'z');
}
return lst;
}
template <class T> template <class T>
T randomObject(); T randomObject();
template <> template <>
int randomObject<int>() { int randomObject<int>();
return random(0, 1024);
}
template <> template <>
std::string randomObject<std::string>() { std::string randomObject<std::string>();
std::string result;
randomString(&result);
return result;
}
template <> template <>
folly::fbstring randomObject<folly::fbstring>() { folly::fbstring randomObject<folly::fbstring>();
folly::fbstring result;
randomString(&result);
return result;
}
#define CONCAT(A, B) CONCAT_HELPER(A, B) #define CONCAT(A, B) CONCAT_HELPER(A, B)
#define CONCAT_HELPER(A, B) A##B #define CONCAT_HELPER(A, B) A##B
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment