Started replacing DataBlockFixture with DataFixture.

Step 1: Create DataFixture
This commit is contained in:
Sebastian Messmer 2015-04-25 13:20:26 +02:00
parent 38327de0c8
commit 40451e762c
2 changed files with 39 additions and 0 deletions

23
data/DataFixture.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "DataFixture.h"
namespace cpputils {
Data DataFixture::generate(size_t size, long long int seed) {
Data result(size);
long long int val = seed;
for(size_t i=0; i<size/sizeof(long long int); ++i) {
//MMIX linear congruential generator
val *= 6364136223846793005L;
val += 1442695040888963407;
reinterpret_cast<long long int*>(result.data())[i] = val;
}
uint64_t alreadyWritten = (size/sizeof(long long int))*sizeof(long long int);
val *= 6364136223846793005L;
val += 1442695040888963407;
char *remainingBytes = reinterpret_cast<char*>(&val);
//Fill remaining bytes
for(size_t i=0; i<size-alreadyWritten; ++i) {
reinterpret_cast<char*>(result.data())[alreadyWritten + i] = remainingBytes[i];
}
return result;
}
}

16
data/DataFixture.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#ifndef MESSMER_CPP_UTILS_DATA_DATAFIXTURE_H_
#define MESSMER_CPP_UTILS_DATA_DATAFIXTURE_H_
#include "Data.h"
namespace cpputils {
class DataFixture {
public:
static Data generate(size_t size, long long int seed = 1);
};
}
#endif