yadro-task/tests/generate_input.cpp
erius f8bfc78cad Updated README.md to include additional info about this project
Implemented reading settings from config file
ftsort now outputs total runtime in ms and peak virtual memory usage
Added some error handling
Added documenation to tape_config.h
Changed catch2 cmake dependency to be resolved using FetchContent
Added generate_input test binary to generate big input tape data sets
Header inclusion path changed to _include_ directory, so that tapelib has to be explicitly specified in include directrives
2024-10-28 05:23:42 +03:00

35 lines
1.1 KiB
C++

#include "tapelib/filetape.h"
#include <cstddef>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
#include <string>
/**
* Generate big input data sets for external sort testing.
* Takes 2 positional arguments - first one is the ouput file name,
* secon one is the amount of random cells that will be generated.
* Each cell value is in range [0; RAND_MAX]
*/
int main(int argc, char *argv[]) {
if (argc < 3) {
std::cerr << "Not enough arguments" << std::endl;
return -1;
}
std::string out_name = argv[1]; // NOLINT
size_t cells = std::stoi(argv[2]); // NOLINT
std::ofstream out(out_name);
if (!out.is_open()) {
std::cerr << "Failed to open file" << std::endl;
return -1;
}
srand(time(nullptr));
out << std::setfill('0') << std::setw(tape::FT_CELL_SIZE)
<< std::to_string(rand());
for (size_t i = 1; i < cells; i++) {
out << tape::FT_DELIMETER << std::setfill('0')
<< std::setw(tape::FT_CELL_SIZE) << std::to_string(rand());
}
return 0;
}