本文整理汇总了C++中FixedArray::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ FixedArray::Write方法的具体用法?C++ FixedArray::Write怎么用?C++ FixedArray::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FixedArray
的用法示例。
在下文中一共展示了FixedArray::Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is
TEST(FixedArray, random){
for (int iter = 0; iter < 10; ++iter){
const uint64_t N = rand() % 10000;
const uint64_t shift = rand() % 32;
const uint64_t val_max = 1LLU << shift;
FixedArray array;
vector<uint64_t> vals;
uint64_t max_val = 0;
for (uint64_t i = 0; i < N; ++i){
uint64_t v = rand() % val_max;
if (max_val < v){
max_val = v;
}
array.PushBack(v);
vals.push_back(v);
}
uint64_t len = 0;
for (; len < 64 && max_val >> len; ++len){
}
ASSERT_EQ(N, array.num());
ASSERT_EQ(len, array.len());
for (uint64_t i = 0; i < N; ++i){
ASSERT_EQ(vals[i], array.Get(i));
}
ostringstream os;
array.Write(os);
FixedArray array2;
istringstream is(os.str());
array2.Read(is);
ASSERT_EQ(N, array2.num());
ASSERT_EQ(len, array2.len());
for (uint64_t i = 0; i < N; ++i){
ASSERT_EQ(vals[i], array2.Get(i));
}
}
}