From 32e2d48cd31d20d80ecd7cd87ecfe74c2bbc1e5a Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 10 Nov 2023 12:40:10 -0500 Subject: [PATCH] worsen logging --- include/blt/std/logging.h | 29 ++-- src/tests/binary_trees.h | 43 ++++++ src/tests/hashmap_tests.h | 18 +++ src/tests/logging.h | 30 +++++ src/tests/main.cpp | 261 ++++++++++++++++++++++++++++++++++++ src/tests/nbt_tests.cpp | 160 ++++++++++++++++++++++ src/tests/nbt_tests.h | 41 ++++++ src/tests/profiling_tests.h | 64 +++++++++ src/tests/queue_tests.h | 148 ++++++++++++++++++++ 9 files changed, 780 insertions(+), 14 deletions(-) create mode 100755 src/tests/binary_trees.h create mode 100755 src/tests/hashmap_tests.h create mode 100755 src/tests/logging.h create mode 100755 src/tests/main.cpp create mode 100755 src/tests/nbt_tests.cpp create mode 100755 src/tests/nbt_tests.h create mode 100755 src/tests/profiling_tests.h create mode 100755 src/tests/queue_tests.h diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h index ccd65ef..6b19ab8 100755 --- a/include/blt/std/logging.h +++ b/include/blt/std/logging.h @@ -13,6 +13,7 @@ #include #include #include +#include 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); @@ -138,20 +139,25 @@ namespace blt::logging } template - 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) { - log_internal(std::to_string(t), level, file, line); - } else if constexpr (std::is_same_v || std::is_same_v) + log_internal(std::to_string(t), level, file, line, args); + } else if constexpr (std::is_same_v) { - log_internal(t, level, file, line); + log_internal(t, level, file, line, args); + } else if constexpr (std::is_same_v){ + log_internal(std::string(t), level, file, line, args); } else { std::stringstream stream; stream << t; - log_internal(stream.str(), level, file, line); + log_internal(stream.str(), level, file, line, args); } + va_end(args); } template @@ -480,7 +486,7 @@ namespace blt::logging { 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 va_list args_copy; va_copy(args_copy, args); @@ -560,10 +566,7 @@ namespace blt::logging { return out; } - void log_internal(const std::string& format, log_level level, const char* file, int line, ...) { - va_list args; - va_start(args, line); - + void log_internal(const std::string& format, log_level level, const char* file, int line, std::va_list& args) { std::string withoutLn = format; auto len = withoutLn.length(); @@ -616,8 +619,6 @@ namespace blt::logging { writer.writeLine(path, stripANSI(finalFormattedOutput)); } //std::cout.flush(); - - va_end(args); } void log_stream_internal(const std::string& str, const logger& logger) { @@ -692,7 +693,7 @@ namespace blt::logging { #define BLT_ERROR(format, ...) #define BLT_FATAL(format, ...) #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__} #ifdef BLT_DISABLE_TRACE #define BLT_TRACE(format, ...) diff --git a/src/tests/binary_trees.h b/src/tests/binary_trees.h new file mode 100755 index 0000000..33e0d8b --- /dev/null +++ b/src/tests/binary_trees.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include +#include + +void printBinaryTree(blt::node_binary_search_tree& 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 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"; + + +} \ No newline at end of file diff --git a/src/tests/hashmap_tests.h b/src/tests/hashmap_tests.h new file mode 100755 index 0000000..db7ef64 --- /dev/null +++ b/src/tests/hashmap_tests.h @@ -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 + +inline static int test_hashmaps(){ + + + return 0; +} + +#endif //BLT_TESTS_HASHMAP_TEXTS_H diff --git a/src/tests/logging.h b/src/tests/logging.h new file mode 100755 index 0000000..c38ea99 --- /dev/null +++ b/src/tests/logging.h @@ -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 diff --git a/src/tests/main.cpp b/src/tests/main.cpp new file mode 100755 index 0000000..ffcc664 --- /dev/null +++ b/src/tests/main.cpp @@ -0,0 +1,261 @@ + +#include +//#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 +//#include "hashmap_tests.h" +//#include + +std::function 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 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(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; +} \ No newline at end of file diff --git a/src/tests/nbt_tests.cpp b/src/tests/nbt_tests.cpp new file mode 100755 index 0000000..cca0bc6 --- /dev/null +++ b/src/tests/nbt_tests.cpp @@ -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 +#include +#include +#include +#include +#include + +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(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(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("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() +{ + +} diff --git a/src/tests/nbt_tests.h b/src/tests/nbt_tests.h new file mode 100755 index 0000000..187023d --- /dev/null +++ b/src/tests/nbt_tests.h @@ -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 +#include + +namespace blt::tests { + + template + 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::min(), std::numeric_limits::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 diff --git a/src/tests/profiling_tests.h b/src/tests/profiling_tests.h new file mode 100755 index 0000000..dcd26e3 --- /dev/null +++ b/src/tests/profiling_tests.h @@ -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& 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 diff --git a/src/tests/queue_tests.h b/src/tests/queue_tests.h new file mode 100755 index 0000000..758c4e8 --- /dev/null +++ b/src/tests/queue_tests.h @@ -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 +#include +#include +#include +#include +#include + +std::array values{}; + +std::queue base_queue{}; +blt::flat_queue blt_flat_queue{}; +blt::flat_stack 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 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