From 7693791783bfaedca46d3c3fdc14fa5d8260c4ca Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Sat, 16 Oct 2021 03:03:21 +0200 Subject: [PATCH] More test coverage --- Makefile | 9 +++-- tests/math.cpp | 52 ++++++++++++++++++++++++++- tests/pair_test.cpp | 77 +++++++++++++++++++++++++++++++++++++++- tests/pointers_test.cpp | 42 ++++++++++++++++++++++ tests/tmp_manip_test.cpp | 31 ++++++++++++++++ 5 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 tests/pointers_test.cpp create mode 100644 tests/tmp_manip_test.cpp diff --git a/Makefile b/Makefile index afbae8b..b8c758b 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,13 @@ CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=100 -DNO_BENCH= EVERY_USEFUL_FILE= $(shell find include/ -name "*.hpp" -type "f") EVERY_TEST_FILE= $(shell find tests/ -name "*.cpp" -type "f") +TEST_OBJECTS := $(EVERY_TEST_FILE:%.cpp=bin/obj/%.test.o) all: tests +bin/obj/%.test.o: %.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) -DUSE_CATCH -Itests -Iinclude -o $@ -c $< + docs: $(EVERY_USEFUL_FILE) doxygen doxy.config @@ -18,9 +23,9 @@ tests: bin/tests @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata $(EVERY_USEFUL_FILE) @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata $(EVERY_USEFUL_FILE) | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' -bin/tests: tests.cpp $(EVERY_TEST_FILE) $(EVERY_USEFUL_FILE) ./tests/test_scaffold.h +bin/tests: tests.cpp $(TEST_OBJECTS) $(EVERY_USEFUL_FILE) ./tests/test_scaffold.h @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -Itests -Iinclude tests.cpp $(EVERY_TEST_FILE) -o $@ + $(CXX) $(CXXFLAGS) -Itests -Iinclude tests.cpp $(TEST_OBJECTS) -o $@ clean: ./bin @rm -rf $< \ No newline at end of file diff --git a/tests/math.cpp b/tests/math.cpp index af47f47..7edff01 100644 --- a/tests/math.cpp +++ b/tests/math.cpp @@ -1,5 +1,6 @@ #include "test_scaffold.h" #include "gp/containers/array.hpp" +#include "gp/utils/pair.hpp" #include "gp/math.hpp" #include "gp/math/rendering/renderer.hpp" #include "gp/math/rendering/bmp_viewport.hpp" @@ -9,7 +10,10 @@ #include #include #include +#include +#include +typedef std::mt19937_64 cheap_rand; struct sin_test : public test_scaffold { sin_test() { @@ -177,4 +181,50 @@ struct function_test : public test_scaffold { } }; -append_test dummy_ml8576f(new function_test{}); \ No newline at end of file +append_test dummy_ml8576f(new function_test{}); + + +template +struct math_funcs_test : public test_scaffold { + uint32_t seed; + T low; + T high; + math_funcs_test(T low = std::numeric_limits::min(), T high = std::numeric_limits::max()) { + this->low = low; + this->high = high; + seed = std::random_device{}(); + name = __FILE__ ":4_sort_pair"; + name += std::to_string(seed); + } + + virtual int run() { + + cheap_rand setter(seed); + + bool result = true; + std::uniform_real_distribution dist{low, high}; + for(int i = 0 ; i < 10000; i++) + { + // TODO: Verify things, like, for real + gp::pair v{dist(setter), dist(setter)}; + gp::pair + floorsign{gp::math::floor(v.first), gp::math::sign(v.second)}, + sincos{gp::math::sin(v.first), gp::math::cos(v.second)}, + isqrt{gp::math::isqrt(v.first), gp::math::fast_isqrt(v.second)}; + double tan_v = gp::math::tan(dist(setter)); + double sign_v = gp::math::sign(0); + + result += floorsign.first > v.first; + result += gp::math::abs(floorsign.second) == 1; + + //result = ascending.first == descending.second ? result : false; + } + + return !result; + } +}; + +append_test dummy_5qsz5ert443(new math_funcs_test{}); +append_test dummy_436z5ert443(new math_funcs_test{}); +append_test dummy_mqlsdf123(new math_funcs_test{-10,10}); +append_test dummy_mqlsdf456(new math_funcs_test{-10,10}); \ No newline at end of file diff --git a/tests/pair_test.cpp b/tests/pair_test.cpp index c3f4bf0..2386e4c 100644 --- a/tests/pair_test.cpp +++ b/tests/pair_test.cpp @@ -1,4 +1,5 @@ #include "gp/utils/pair.hpp" +#include "gp/algorithms/min_max.hpp" #include "test_scaffold.h" #include @@ -33,4 +34,78 @@ struct pair_test : public test_scaffold { } }; -append_test dummy_rsly21r43(new pair_test{}); \ No newline at end of file +append_test dummy_rsly21r43(new pair_test{}); + +template +struct sort_pair_test : public test_scaffold { + uint32_t seed; + + sort_pair_test() { + seed = std::random_device{}(); + name = __FILE__ ":2_sort_pair"; + name += std::to_string(seed); + } + + virtual int run() { + // TODO: Verify things, like, for real + + cheap_rand setter(seed); + + bool result = true; + std::uniform_real_distribution dist{-1.0, 1.0}; + for(int i = 0 ; i < 10000; i++) + { + gp::pair v{dist(setter), dist(setter)}; + gp::pair + ascending{gp::min(v.first, v.second), gp::max(v.first, v.second)}, + descending{gp::max(v.first, v.second), gp::min(v.first, v.second)}, + clamped{gp::clamp(0.25,v.first, 0.5), gp::min(0.5, v.first, v.second)}, + minmaxed{gp::min(dist(setter), dist(setter), dist(setter)), gp::max(dist(setter), dist(setter), dist(setter))}, + rngclamp{gp::clamp(dist(setter),dist(setter), dist(setter)), gp::clamp(dist(setter), dist(setter), dist(setter))}; + result = ascending.first == descending.second ? result : false; + } + + return !result; + } +}; + +append_test dummy_5qsd5r43(new sort_pair_test{}); +append_test dummy_4365xv43(new sort_pair_test{}); + +template +struct sort_pair_test2 : public test_scaffold { + uint32_t seed; + + sort_pair_test2() { + seed = std::random_device{}(); + name = __FILE__ ":3_sort_pair2"; + name += std::to_string(seed); + } + + virtual int run() { + // TODO: Verify things, like, for real + + cheap_rand setter(seed); + + bool result = true; + std::uniform_int_distribution dist{0, 4096}; + for(int i = 0 ; i < 10000; i++) + { + gp::pair v{dist(setter), dist(setter)}; + gp::pair + ascending{gp::min(v.first, v.second), gp::max(v.first, v.second)}, + descending{gp::max(v.first, v.second), gp::min(v.first, v.second)}, + clamped{gp::clamp(512,v.first, 1024), gp::min(1024, v.first, v.second)}, + minmaxed{gp::min(dist(setter),dist(setter), dist(setter)), gp::max(dist(setter), dist(setter), dist(setter))}, + rngclamp{gp::clamp(dist(setter),dist(setter), dist(setter)), gp::clamp(dist(setter), dist(setter), dist(setter))}; + result = ascending.first == descending.second ? result : false; + } + + return !result; + } +}; + +append_test dummy_5zegfh43(new sort_pair_test2{}); +append_test dummy_sdghtfh4(new sort_pair_test2{}); +append_test dummy_judlg8gb(new sort_pair_test2{}); +append_test dummy_5egkzbcd(new sort_pair_test2{}); \ No newline at end of file diff --git a/tests/pointers_test.cpp b/tests/pointers_test.cpp new file mode 100644 index 0000000..3f3b286 --- /dev/null +++ b/tests/pointers_test.cpp @@ -0,0 +1,42 @@ +#include "gp/utils/pointers.hpp" +#include "gp/utils/allocators/arena.hpp" +#include "test_scaffold.h" +#include "allocator.hpp" +#include + + +struct unique_ptr_test : public test_scaffold { + uint32_t seed; + + unique_ptr_test() { + name = __FILE__ ":1"; + } + + virtual int run() { + std::unique_ptr> store = std::make_unique>(); + gp::arena alloc{&*store->begin(), store->size()}; + auto v = gp::unique_ptr::make(alloc, 1024); + + return !v; + } +}; + +append_test dummy_45sdf543(new unique_ptr_test{}); + +struct unique_ptr2_test : public test_scaffold { + uint32_t seed; + + unique_ptr2_test() { + name = __FILE__ ":2"; + } + + virtual int run() { + std::unique_ptr> store = std::make_unique>(); + gp::arena alloc{&*store->begin(), store->size()}; + auto v = gp::unique_ptr::make(alloc, "1024"); + + return !(*(v->begin()) == '1' && v); + } +}; + +append_test dummy_aguhdff543(new unique_ptr2_test{}); \ No newline at end of file diff --git a/tests/tmp_manip_test.cpp b/tests/tmp_manip_test.cpp new file mode 100644 index 0000000..6b9348e --- /dev/null +++ b/tests/tmp_manip_test.cpp @@ -0,0 +1,31 @@ +#include "gp/algorithms/tmp_manip.hpp" +#include "test_scaffold.h" + + +struct max_size_test : public test_scaffold { + uint32_t seed; + + max_size_test() { + name = __FILE__ ":1"; + } + + virtual int run() { + return gp::max_size() != 8; + } +}; + +append_test dummy_lfhz1r43(new max_size_test{}); + +struct fixed_size_test : public test_scaffold { + uint32_t seed; + + fixed_size_test() { + name = __FILE__ ":1"; + } + + virtual int run() { + return !(gp::is_fixed_size() && gp::is_fixed_size() && !gp::is_fixed_size()); + } +}; + +append_test dummy_sjuige443(new fixed_size_test{}); \ No newline at end of file