worsen logging

v1
Brett 2023-11-10 12:40:10 -05:00
parent bd7976cf71
commit 32e2d48cd3
9 changed files with 780 additions and 14 deletions

View File

@ -13,6 +13,7 @@
#include <sstream> #include <sstream>
#include <blt/config.h> #include <blt/config.h>
#include <iostream> #include <iostream>
#include <cstdarg>
namespace blt::logging namespace blt::logging
{ {
@ -116,7 +117,7 @@ namespace blt::logging
}; };
void log_internal(const std::string& format, log_level level, const char* file, int line, ...); void log_internal(const std::string& format, log_level level, const char* file, int line, std::va_list& args);
void log_stream_internal(const std::string& str, const logger& logger); void log_stream_internal(const std::string& str, const logger& logger);
@ -138,20 +139,25 @@ namespace blt::logging
} }
template<typename T> template<typename T>
inline void log(T t, log_level level, const char* file, int line) inline void log(T t, log_level level, const char* file, int line, ...)
{ {
std::va_list args;
va_start(args, line);
if constexpr (std::is_arithmetic_v<T>) if constexpr (std::is_arithmetic_v<T>)
{ {
log_internal(std::to_string(t), level, file, line); log_internal(std::to_string(t), level, file, line, args);
} else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, const char*>) } else if constexpr (std::is_same_v<T, std::string>)
{ {
log_internal(t, level, file, line); log_internal(t, level, file, line, args);
} else if constexpr (std::is_same_v<T, const char*>){
log_internal(std::string(t), level, file, line, args);
} else } else
{ {
std::stringstream stream; std::stringstream stream;
stream << t; stream << t;
log_internal(stream.str(), level, file, line); log_internal(stream.str(), level, file, line, args);
} }
va_end(args);
} }
template<typename T> template<typename T>
@ -480,7 +486,7 @@ namespace blt::logging {
return out; return out;
} }
void applyCFormatting(const std::string& format, std::string& output, va_list& args){ void applyCFormatting(const std::string& format, std::string& output, std::va_list& args){
// args must be copied because they will be consumed by the first vsnprintf // args must be copied because they will be consumed by the first vsnprintf
va_list args_copy; va_list args_copy;
va_copy(args_copy, args); va_copy(args_copy, args);
@ -560,10 +566,7 @@ namespace blt::logging {
return out; return out;
} }
void log_internal(const std::string& format, log_level level, const char* file, int line, ...) { void log_internal(const std::string& format, log_level level, const char* file, int line, std::va_list& args) {
va_list args;
va_start(args, line);
std::string withoutLn = format; std::string withoutLn = format;
auto len = withoutLn.length(); auto len = withoutLn.length();
@ -616,8 +619,6 @@ namespace blt::logging {
writer.writeLine(path, stripANSI(finalFormattedOutput)); writer.writeLine(path, stripANSI(finalFormattedOutput));
} }
//std::cout.flush(); //std::cout.flush();
va_end(args);
} }
void log_stream_internal(const std::string& str, const logger& logger) { void log_stream_internal(const std::string& str, const logger& logger) {
@ -692,7 +693,7 @@ namespace blt::logging {
#define BLT_ERROR(format, ...) #define BLT_ERROR(format, ...)
#define BLT_FATAL(format, ...) #define BLT_FATAL(format, ...)
#else #else
#define BLT_LOG(format, level, ...) blt::logging::log_internal(format, level, __FILE__, __LINE__, ##__VA_ARGS__) #define BLT_LOG(format, level, ...) blt::logging::log(format, level, __FILE__, __LINE__, ##__VA_ARGS__)
#define BLT_LOG_STREAM(level) blt::logging::logger{level, __FILE__, __LINE__} #define BLT_LOG_STREAM(level) blt::logging::logger{level, __FILE__, __LINE__}
#ifdef BLT_DISABLE_TRACE #ifdef BLT_DISABLE_TRACE
#define BLT_TRACE(format, ...) #define BLT_TRACE(format, ...)

43
src/tests/binary_trees.h Executable file
View File

@ -0,0 +1,43 @@
#pragma once
#include <blt/std/binary_tree.h>
#include <blt/std/random.h>
#include <blt/std/time.h>
#include <blt/std/string.h>
#include <iostream>
void printBinaryTree(blt::node_binary_search_tree<long>& tree) {
auto nodes = tree.inOrderTraverse();
for (auto n : nodes)
std::cout << n->payload << " ";
std::cout << "\n";
}
void binaryTreeTest(){
using namespace blt;
node_binary_search_tree<long> dataTree;
dataTree.insert(6);
dataTree.insert(3);
dataTree.insert(2);
dataTree.insert(4);
dataTree.insert(10);
dataTree.insert(13);
dataTree.insert(8);
dataTree.insert(16);
printBinaryTree(dataTree);
auto searchedNode = dataTree.search(10);
std::cout << "10's children: "<< searchedNode->left->payload << ", " << searchedNode->right->payload << "\n";
dataTree.remove(6);
printBinaryTree(dataTree);
//searchedNode = dataTree.search(8);
//std::cout << "8's children: "<< searchedNode->left->payload << ", " << searchedNode->right->payload << "\n";
}

18
src/tests/hashmap_tests.h Executable file
View File

@ -0,0 +1,18 @@
/*
* Created by Brett on 31/03/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_HASHMAP_TEXTS_H
#define BLT_TESTS_HASHMAP_TEXTS_H
#include <blt/std/hashmap.h>
inline static int test_hashmaps(){
return 0;
}
#endif //BLT_TESTS_HASHMAP_TEXTS_H

30
src/tests/logging.h Executable file
View File

@ -0,0 +1,30 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_LOGGING_TEST_H
#define BLT_TESTS_LOGGING_TEST_H
void run_logging() {
BLT_TRACE(10);
BLT_TRACE(10.5);
BLT_TRACE("Hello %d World!\n", 50);
BLT_DEBUG("Hello %E World!\n", 1205200.0);
BLT_INFO("Hello World!\n");
BLT_WARN("Hello World!\n");
BLT_ERROR("Hello World!\n");
BLT_FATAL("Hello World!\n");
// blt::logging::trace << "Hello! " << "Double stream insertion! " << 51 << 65 << " ";
// blt::logging::trace << "Same Line! ";
// blt::logging::trace << "Write the end!\n";
// blt::logging::trace << "Seeee\n Super\n";
std::string hello = "superSexyMax";
std::cout << "String starts with: " << blt::string::contains(hello, "superSexyMaxE") << "\n";
}
#endif //BLT_TESTS_LOGGING_H

261
src/tests/main.cpp Executable file
View File

@ -0,0 +1,261 @@
#include <unordered_map>
//#include "binary_trees.h"
//#include "logging.h"
#include "profiling_tests.h"
#include "nbt_tests.h"
#include "blt/parse/argparse.h"
//#include "queue_tests.h"
//#include "blt/math/vectors.h"
//#include "blt/math/matrix.h"
//#include <bitset>
//#include "hashmap_tests.h"
//#include <functional>
std::function<int(int i)> test{
[](int i) -> int {
int acc = 1;
for (int j = 0; j < i; j++)
{
acc += j * i;
}
return acc;
}
};
int test_as_func(int i)
{
int acc = 1;
for (int j = 0; j < i; j++)
{
acc += j * i;
}
return acc;
}
inline int test_as_func_inline(int i)
{
int acc = 1;
for (int j = 0; j < i; j++)
{
acc += j * i;
}
return acc;
}
std::function<int(int i)> test_func_as_std(&test_as_func);
class super_func
{
public:
virtual int test(int i) = 0;
virtual ~super_func() = default;
};
class class_func : public super_func
{
public:
int test(int i) override
{
int acc = 1;
for (int j = 0; j < i; j++)
{
acc += j * i;
}
return acc;
}
};
int (* func_func)(int) = [](int i) -> int {
int acc = 1;
for (int j = 0; j < i; j++)
{
acc += j * i;
}
return acc;
};
int (* func_func_in)(int) = &test_as_func;
int main(int argc, const char** argv)
{
blt::arg_parse parser;
parser.addArgument(blt::arg_builder({"-c", "--no-color"}).setAction(blt::arg_action_t::STORE_TRUE).build());
parser.addArgument(
blt::arg_builder("--nbt")
.setHelp("Run NBT tests. Accepts optional # of bytes to write. Default: 1mb")
.setMetavar("bytes")
.setAction(blt::arg_action_t::STORE)
.setNArgs('?').build());
auto args = parser.parse_args(argc, argv);
if (args.contains("--no-color"))
{
for (int i = (int) blt::logging::log_level::NONE; i < (int) blt::logging::log_level::FATAL; i++)
blt::logging::setLogColor((blt::logging::log_level) i, "");
blt::logging::setLogOutputFormat("[${{TIME}}] [${{LOG_LEVEL}}] (${{FILE}}:${{LINE}}) ${{STR}}\n");
}
if (args.contains("--nbt"))
{
auto v = blt::arg_parse::get<std::string>(args["nbt"]);
if (v.empty())
v = "1048576";
blt::tests::nbtFSTest(std::stoul(v));
blt::tests::nbtWrite();
blt::tests::nbtRead();
}
//
// auto* funy = new class_func;
// super_func* virtual_funy = new class_func;
//
// for (int _ = 0; _ < 10; _++ ) {
// int num_of_tests = 10000;
// int acc = 1;
// BLT_START_INTERVAL("Functions Test", "std::function (lambda)");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += test(i);
// }
// BLT_END_INTERVAL("Functions Test", "std::function (lambda)");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "std::function (normal)");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += test_func_as_std(i);
// }
// BLT_END_INTERVAL("Functions Test", "std::function (normal)");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "normal function");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += test_as_func(i);
// }
// BLT_END_INTERVAL("Functions Test", "normal function");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "(inline) normal function");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += test_as_func_inline(i);
// }
// BLT_END_INTERVAL("Functions Test", "(inline) normal function");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "virtual class direct");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += funy->test(i);
// }
// BLT_END_INTERVAL("Functions Test", "virtual class direct");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "virtual class");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += virtual_funy->test(i);
// }
// BLT_END_INTERVAL("Functions Test", "virtual class");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "funcptr lambda");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += func_func(i);
// }
// BLT_END_INTERVAL("Functions Test", "funcptr lambda");
// BLT_TRACE(acc);
//
// BLT_START_INTERVAL("Functions Test", "c function ptr");
// acc = 1;
// for (int i = 0; i < num_of_tests; i++) {
// acc += func_func_in(i);
// }
// BLT_END_INTERVAL("Functions Test", "c function ptr");
// BLT_TRACE(acc);
// }
//
// BLT_PRINT_PROFILE("Functions Test", blt::logging::log_level::NONE, true);
// delete virtual_funy;
// delete funy;
//
// binaryTreeTest();
//
// run_logging();
//
// runProfilingAndTableTests();
//
// blt::logging::flush();
//
// nbt_tests();
//
// BLT_TRACE0_STREAM << "Test Output!\n";
// BLT_TRACE1_STREAM << 5 << "\n";
// BLT_TRACE2_STREAM << 5 << "\n";
// BLT_TRACE3_STREAM << 5 << "\n";
// BLT_TRACE_STREAM << "TRACEY\n";
//
// blt::logging::flush();
//
// test_queues();
//
// blt::vec4 v{2, 5, 1, 8};
// blt::mat4x4 m{};
// m.m(0,0, 1);
// m.m(0,2, 2);
// m.m(1, 1, 3);
// m.m(1, 3, 4);
// m.m(2, 2, 5);
// m.m(3, 0, 6);
// m.m(3, 3, 7);
//
// auto result = m * v;
//
// std::cout << result.x() << " " << result.y() << " " << result.z() << " " << result.w() << std::endl;
//
// if (test_hashmaps()){
// BLT_FATAL("Hashmap test failed!");
// return 1;
// }
//
// BLT_TRACE("Hello Trace!");
// BLT_DEBUG("Hello Debug!");
// BLT_INFO("Hello Info!");
// BLT_WARN("Hello Warn!");
// BLT_ERROR("Hello Error!");
// BLT_FATAL("Hello Fatal!");
//
// constexpr int size = 100;
// uint32_t vals[size];
//
// for (uint32_t & val : vals)
// val = 0;
//
// uint32_t seed = 1023;
// for (int i = 0; i < 10000000; i++){
// seed = seed * i;
// vals[blt::random::randomInt(seed, 0, size)] += 1;
// }
//
// uint32_t mean = 0;
// for (uint32_t& val : vals)
// mean += val;
// mean /= size;
//
// uint32_t std = 0;
// for (uint32_t& val : vals) {
// auto e = (val - mean);
// std += e * e;
// }
//
// auto stdev = sqrt((double)std / (double)size);
//
// BLT_INFO("STDDEV of # random values: %f", stdev);
return 0;
}

160
src/tests/nbt_tests.cpp Executable file
View File

@ -0,0 +1,160 @@
/*
* Created by Brett on 11/08/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#include "nbt_tests.h"
#include <blt/nbt/nbt.h>
#include <blt/profiling/profiler.h>
#include <blt/std/logging.h>
#include <blt/std/format.h>
#include <blt/std/filesystem.h>
#include <filesystem>
void blt::tests::nbtFSBlockRead(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr)
{
}
void blt::tests::nbtFSBlockWrite(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr)
{
std::fstream out("fs_tests/test_block_fs_" + std::to_string(buff_size) + ".all", std::ios::out | std::ios::binary);
blt::fs::fstream_block_writer writer(out, buff_size);
auto str = "fs::block::" + std::to_string(buff_size);
BLT_START_INTERVAL("Write Tests", str);
for (size_t _ = 0; _ < num_array; _++)
writer.write(reinterpret_cast<char*>(arr[_]), arr_size);
BLT_END_INTERVAL("Write Tests", str);
}
void blt::tests::nbtFSRead(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr)
{
}
void blt::tests::nbtFSWrite(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr)
{
std::fstream out("fs_tests/test_fs_" + std::to_string(buff_size) + ".all", std::ios::out | std::ios::binary);
auto str = "fs::std::" + std::to_string(buff_size);
BLT_START_INTERVAL("Write Tests", str);
for (size_t _ = 0; _ < num_array; _++)
out.write(reinterpret_cast<const char*>(arr[_]), (long)arr_size);
BLT_END_INTERVAL("Write Tests", str);
}
void blt::tests::nbtFSTest(size_t total_size)
{
std::filesystem::create_directory("fs_tests/");
for (int i = 10; i < 20; i++)
{
auto buff_size = (size_t) std::pow(2, i);
auto arr_size = 512 * 1;
auto num_array = (total_size) / arr_size;
auto* arr = new unsigned char* [num_array];
for (size_t _ = 0; _ < num_array; _++)
{
arr[_] = new unsigned char[arr_size];
generateRandomData(arr[_], arr_size, _);
}
nbtFSBlockWrite(buff_size, arr_size, num_array, arr);
nbtFSWrite(buff_size, arr_size, num_array, arr);
for (size_t _ = 0; _ < num_array; _++)
delete[] arr[_];
delete[] arr;
}
BLT_PRINT_PROFILE("Write Tests");
}
void blt::tests::nbtRawRead()
{
}
void blt::tests::nbtRawWrite()
{
}
void blt::tests::nbtRawTest()
{
}
void blt::tests::nbtRead()
{
std::fstream nbtInputFile("super_file.nbt", std::ios::in | std::ios::binary);
blt::fs::fstream_block_reader blockReader(nbtInputFile);
blt::nbt::NBTReader nbtReader(blockReader);
nbtReader.read();
auto shortTag = nbtReader.getTag<blt::nbt::tag_short>("shortTest");
BLT_TRACE("Got short: %d", shortTag->get());
}
void blt::tests::nbtWrite()
{
std::fstream nbtFile("super_file.nbt", std::ios::out | std::ios::binary);
blt::fs::fstream_block_writer blockWriter(nbtFile);
blt::nbt::NBTWriter nbtWriter(blockWriter);
nbtWriter.write(
new blt::nbt::tag_compound(
"root", {
new blt::nbt::tag_byte("super_byte", 8),
new blt::nbt::tag_short("shortTest", 32767),
new blt::nbt::tag_compound(
"SEXY_COMPOUND", {
new blt::nbt::tag_list(
"my list", {
new blt::nbt::tag_long("", 1230),
new blt::nbt::tag_long("", 2),
new blt::nbt::tag_long("", 50340535),
new blt::nbt::tag_long("", 55),
new blt::nbt::tag_long("", 256),
new blt::nbt::tag_long("", 512),
new blt::nbt::tag_long("", 9999999999),
}
),
new blt::nbt::tag_double("OMG IT'S A DOUBLE", 1320.04324),
new blt::nbt::tag_float("OMG IT'S A FLOAT", 12.04324),
new blt::nbt::tag_compound(
"Triple", {
new blt::nbt::tag_int("Test int", 32),
new blt::nbt::tag_byte_array(
"super array", {
51, 23, 12, 04, 33, 53, 11, 22, 3, 93, 120
}
),
new blt::nbt::tag_string("I am a string", "I have stringy contents"),
new blt::nbt::tag_string("name", "Bananrama"),
new blt::nbt::tag_int_array(
"int array", {
1230, 234023, 21300, 2309230, 2340230, 2, 1, 32, 3265, 12, 53, 123, 7,
56, 12
}
),
new blt::nbt::tag_long_array(
"valid", {
1230, 5320, 323200234402304, 230023, 23042034, 230230, 2301203,
123010230, 12300123
}
)
}
)
}
)
}
));
blockWriter.flush();
nbtFile.close();
}
void blt::tests::nbtTest()
{
}

41
src/tests/nbt_tests.h Executable file
View File

@ -0,0 +1,41 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_NBT_TESTS_H
#define BLT_TESTS_NBT_TESTS_H
#include <blt/std/random.h>
#include <cstring>
namespace blt::tests {
template<typename T>
T* generateRandomData(T* arr, size_t size, uint32_t seed = 0) {
for (size_t i = 0; i < size; i++)
arr[i] = blt::random::randomInt_c(i * size + seed, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
return arr;
}
// test block fs vs std::ios
void nbtFSBlockRead(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr);
void nbtFSBlockWrite(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr);
void nbtFSRead(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr);
void nbtFSWrite(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr);
void nbtFSTest(size_t total_size);
// test raw ios r/w speeds
void nbtRawRead();
void nbtRawWrite();
void nbtRawTest();
// test nbt r/w speeds
void nbtRead();
void nbtWrite();
void nbtTest();
}
#endif //BLT_TESTS_NBT_TESTS_H

64
src/tests/profiling_tests.h Executable file
View File

@ -0,0 +1,64 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_PROFILING_TESTS_H
#define BLT_TESTS_PROFILING_TESTS_H
#include "blt/profiling/profiler.h"
#include "blt/std/logging.h"
#include "blt/std/time.h"
#include "blt/std/format.h"
void print(const std::vector<std::string>& vtr) {
for (const auto& line : vtr)
BLT_TRACE(line);
}
static void runProfilingAndTableTests() {
BLT_START_INTERVAL("Help", "SuperSet");
BLT_END_INTERVAL("Help", "SuperSet");
BLT_START_INTERVAL("Help", "SecondSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "SecondSet");
BLT_START_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 15; i++) {
BLT_START_INTERVAL("Help", "UnderSet" + std::to_string(i));
BLT_END_INTERVAL("Help", "UnderSet" + std::to_string(i));
}
BLT_PRINT_PROFILE("Help", blt::logging::log_level::TRACE);
BLT_TRACE("");
blt::string::TableFormatter formatter;
formatter.addColumn(blt::string::TableColumn{"Test1"});
formatter.addColumn(blt::string::TableColumn{"Test2"});
formatter.addColumn(blt::string::TableColumn{"Test Column"});
formatter.addColumn(blt::string::TableColumn{"Test3"});
formatter.addRow({"This", "This LARGE", "222", "5000"});
formatter.addRow({"OTHER", "LARGE", "6", "1"});
formatter.addRow({"hheee", "looo", "m8", "opsiedo"});
print(formatter.createTable(true, true));
BLT_TRACE("");
print(formatter.createTable(false, true));
BLT_TRACE("");
print(formatter.createTable(true, false));
BLT_TRACE("");
print(formatter.createTable(false, false));
BLT_TRACE("");
}
#endif //BLT_TESTS_PROFILING_TESTS_H

148
src/tests/queue_tests.h Executable file
View File

@ -0,0 +1,148 @@
/*
* Created by Brett on 28/02/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_QUEUE_TESTS_H
#define BLT_TESTS_QUEUE_TESTS_H
#include <queue>
#include <blt/std/queue.h>
#include <blt/std/logging.h>
#include <blt/profiling/profiler.h>
#include <array>
#include <blt/std/random.h>
std::array<int, 15000> values{};
std::queue<int> base_queue{};
blt::flat_queue<int> blt_flat_queue{};
blt::flat_stack<int> blt_flat_stack{};
static inline void fill_queues(){
BLT_START_INTERVAL("Insert", "std::queue");
for (const auto& value : values)
base_queue.push(value);
BLT_END_INTERVAL("Insert", "std::queue");
BLT_START_INTERVAL("Insert", "blt::flat_queue");
for (const auto& value : values)
blt_flat_queue.push(value);
BLT_END_INTERVAL("Insert", "blt::flat_queue");
BLT_START_INTERVAL("Insert", "blt::flat_stack");
for (const auto& value : values)
blt_flat_stack.push(value);
BLT_END_INTERVAL("Insert", "blt::flat_stack");
}
static inline void validate(){
bool std_valid = true;
bool flat_valid = true;
bool stack_valid = true;
BLT_START_INTERVAL("Access", "std::queue");
for (const auto& value : values) {
auto front = base_queue.front();
if (front != value)
std_valid = false;
base_queue.pop();
}
BLT_END_INTERVAL("Access", "std::queue");
BLT_START_INTERVAL("Access", "blt::flat_queue");
for (const auto& value : values) {
auto front = blt_flat_queue.front();
if (front != value)
flat_valid = false;
blt_flat_queue.pop();
}
BLT_END_INTERVAL("Access", "blt::flat_queue");
BLT_START_INTERVAL("Access", "blt::flat_stack");
for (int i = values.size()-1; i > 0; i--) {
const auto& value = values[i];
auto front = blt_flat_stack.top();
if (front != value)
stack_valid = false;
blt_flat_stack.pop();
}
BLT_END_INTERVAL("Access", "blt::flat_stack");
if (!std_valid)
BLT_ERROR("std::queue invalid!");
if (!flat_valid)
BLT_ERROR("blt::flat_queue invalid!");
if (!stack_valid)
BLT_ERROR("blt::stack invalid!");
}
static inline void random_access() {
bool flat_valid = true;
bool stack_valid = true;
BLT_START_INTERVAL("Random", "blt::flat_queue");
for (int i = 0; i < 500; i++) {
auto front = blt_flat_queue.front();
auto next = base_queue.front();
if (front != next)
flat_valid = false;
blt_flat_queue.pop();
base_queue.pop();
}
for (int value : values){
blt_flat_queue.push(value);
base_queue.push(value);
}
for (unsigned int i = 0; i < values.size(); i++) {
auto front = blt_flat_queue.front();
auto next = base_queue.front();
if (front != next)
flat_valid = false;
blt_flat_queue.pop();
base_queue.pop();
}
BLT_END_INTERVAL("Random", "blt::flat_queue");
BLT_START_INTERVAL("Random", "blt::flat_stack");
for (int i = values.size()-1; i > 0; i--) {
const auto& value = values[i];
auto front = blt_flat_stack.top();
if (front != value)
stack_valid = false;
blt_flat_stack.pop();
}
BLT_END_INTERVAL("Random", "blt::flat_stack");
if (!flat_valid)
BLT_ERROR("blt::flat_queue invalid!");
if (!stack_valid)
BLT_ERROR("blt::stack invalid!");
}
static inline void test_queues() {
blt::random::random<int, std::uniform_int_distribution> rand{1, 100};
for (int& value : values){
value = rand.get();
}
fill_queues();
validate();
fill_queues();
random_access();
BLT_PRINT_PROFILE("Insert", blt::logging::log_level::INFO, true);
BLT_PRINT_PROFILE("Access", blt::logging::log_level::INFO, true);
BLT_PRINT_PROFILE("Random", blt::logging::log_level::INFO, true);
}
#endif //BLT_TESTS_QUEUE_TESTS_H