From b4a7ee403560f2413dc4983cf56dae74c14e926f Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 21 Nov 2023 14:22:02 -0500 Subject: [PATCH] move old tests to new tests which are actually old tests --- tests/include/memory_test.h | 40 +++++++++++++ tests/src/main.cpp | 12 ++++ tests/src/memory_test.cpp | 108 ++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 tests/include/memory_test.h create mode 100644 tests/src/memory_test.cpp diff --git a/tests/include/memory_test.h b/tests/include/memory_test.h new file mode 100644 index 0000000..c2bbdd3 --- /dev/null +++ b/tests/include/memory_test.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BLT_TESTS_MEMORY_TEST_H +#define BLT_TESTS_MEMORY_TEST_H + +namespace blt::test::memory +{ + void copy(); + + void move(); + + void access(); + + void ranges(); + + static inline void run() + { + copy(); + move(); + access(); + ranges(); + } +} + +#endif //BLT_TESTS_MEMORY_TEST_H diff --git a/tests/src/main.cpp b/tests/src/main.cpp index ffcc664..da8f1ca 100755 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -11,6 +11,8 @@ //#include //#include "hashmap_tests.h" //#include +#include +#include std::function test{ [](int i) -> int { @@ -81,6 +83,16 @@ int (* func_func_in)(int) = &test_as_func; int main(int argc, const char** argv) { blt::arg_parse parser; + + parser.addArgument( + blt::arg_builder("--memory").setAction(blt::arg_action_t::STORE_TRUE).setNArgs(0).setHelp("Test the blt/std/memory.h file").build()); + + auto args = parser.parse_args(argc, argv); + + if (args.contains("--memory")) + blt::test::memory::run(); + + 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") diff --git a/tests/src/memory_test.cpp b/tests/src/memory_test.cpp new file mode 100644 index 0000000..0680e1a --- /dev/null +++ b/tests/src/memory_test.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2023 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include + +#include +#include +#include +#include +#include + +template +blt::scoped_buffer create_scoped_buffer(size_t size) +{ + static std::random_device dev; + static std::mt19937_64 engine(dev()); + blt::scoped_buffer data(size); + if constexpr (std::is_floating_point_v) + { + static std::uniform_real_distribution dist(std::numeric_limits::min(), std::numeric_limits::max()); + + for (auto& v : data) + v = dist(engine); + } else if (std::is_integral_v) + { + static std::uniform_int_distribution dist(std::numeric_limits::min(), std::numeric_limits::max()); + + for (auto& v : data) + v = dist(engine); + } + return data; +} + +template +blt::scoped_buffer modify_copy(blt::scoped_buffer fill) +{ + for (size_t i = 0; i < size_t(fill.size() / 2); i++) + { + std::swap(fill[i], fill[fill.size() - i - 1]); + } + return fill; +} + +template +T collect(blt::scoped_buffer buff) +{ + T val = 0; + for (auto v : buff) + val = std::max(v, val); + return val; +} + +void blt::test::memory::copy() +{ + BLT_INFO("Running memory copy tests"); + + auto int_buffer_small = create_scoped_buffer(16); + auto int_buffer_medium = create_scoped_buffer(512); + auto int_buffer_large = create_scoped_buffer(8192); + + auto float_buffer_small = create_scoped_buffer(16); + auto float_buffer_medium = create_scoped_buffer(512); + auto float_buffer_large = create_scoped_buffer(8192); + + auto int_small = collect(modify_copy(int_buffer_small)); + auto int_medium = collect(modify_copy(int_buffer_medium)); + auto int_large = collect(modify_copy(int_buffer_large)); + + auto float_small = collect(modify_copy(float_buffer_small)); + auto float_medium = collect(modify_copy(float_buffer_medium)); + auto float_large = collect(modify_copy(float_buffer_large)); + + BLT_TRACE("We collected values [%d, %d, %d]; [%f.0, %f.0, %f.0]", int_small, int_medium, int_large, float_small, float_medium, float_large); +} + +void blt::test::memory::move() +{ + BLT_INFO("Running memory move tests"); + + +} + +void blt::test::memory::access() +{ + BLT_INFO("Running memory construction tests"); + +} + +void blt::test::memory::ranges() +{ + blt::range range(0, 10); + for (auto r : range) + BLT_TRACE_STREAM << r; + BLT_TRACE_STREAM << '\n'; +}