Browse Source

More test coverage

master
Ludovic 'Archivist' Lagouardette 2 years ago
parent
commit
7693791783
5 changed files with 207 additions and 4 deletions
  1. +7
    -2
      Makefile
  2. +51
    -1
      tests/math.cpp
  3. +76
    -1
      tests/pair_test.cpp
  4. +42
    -0
      tests/pointers_test.cpp
  5. +31
    -0
      tests/tmp_manip_test.cpp

+ 7
- 2
Makefile View File

@ -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 $<

+ 51
- 1
tests/math.cpp View File

@ -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 <fstream>
#include <iomanip>
#include <iostream>
#include <random>
#include <string>
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{});
append_test dummy_ml8576f(new function_test{});
template<typename T>
struct math_funcs_test : public test_scaffold {
uint32_t seed;
T low;
T high;
math_funcs_test(T low = std::numeric_limits<T>::min(), T high = std::numeric_limits<T>::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<T> dist{low, high};
for(int i = 0 ; i < 10000; i++)
{
// TODO: Verify things, like, for real
gp::pair<T, T> v{dist(setter), dist(setter)};
gp::pair<T, T>
floorsign{gp::math::floor<T>(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<T>(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<float>{});
append_test dummy_436z5ert443(new math_funcs_test<double>{});
append_test dummy_mqlsdf123(new math_funcs_test<float>{-10,10});
append_test dummy_mqlsdf456(new math_funcs_test<double>{-10,10});

+ 76
- 1
tests/pair_test.cpp View File

@ -1,4 +1,5 @@
#include "gp/utils/pair.hpp"
#include "gp/algorithms/min_max.hpp"
#include "test_scaffold.h"
#include <random>
@ -33,4 +34,78 @@ struct pair_test : public test_scaffold {
}
};
append_test dummy_rsly21r43(new pair_test{});
append_test dummy_rsly21r43(new pair_test{});
template<typename T>
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<T> dist{-1.0, 1.0};
for(int i = 0 ; i < 10000; i++)
{
gp::pair<T, T> v{dist(setter), dist(setter)};
gp::pair<T, T>
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<float>(0.25,v.first, 0.5), gp::min(0.5, v.first, v.second)},
minmaxed{gp::min<T>(dist(setter), dist(setter), dist(setter)), gp::max<T>(dist(setter), dist(setter), dist(setter))},
rngclamp{gp::clamp<T>(dist(setter),dist(setter), dist(setter)), gp::clamp<T>(dist(setter), dist(setter), dist(setter))};
result = ascending.first == descending.second ? result : false;
}
return !result;
}
};
append_test dummy_5qsd5r43(new sort_pair_test<float>{});
append_test dummy_4365xv43(new sort_pair_test<double>{});
template<typename T>
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<T> dist{0, 4096};
for(int i = 0 ; i < 10000; i++)
{
gp::pair<T, T> v{dist(setter), dist(setter)};
gp::pair<T, T>
ascending{gp::min<T>(v.first, v.second), gp::max<T>(v.first, v.second)},
descending{gp::max<T>(v.first, v.second), gp::min<T>(v.first, v.second)},
clamped{gp::clamp<T>(512,v.first, 1024), gp::min(1024, v.first, v.second)},
minmaxed{gp::min<T>(dist(setter),dist(setter), dist(setter)), gp::max<T>(dist(setter), dist(setter), dist(setter))},
rngclamp{gp::clamp<T>(dist(setter),dist(setter), dist(setter)), gp::clamp<T>(dist(setter), dist(setter), dist(setter))};
result = ascending.first == descending.second ? result : false;
}
return !result;
}
};
append_test dummy_5zegfh43(new sort_pair_test2<int>{});
append_test dummy_sdghtfh4(new sort_pair_test2<unsigned long>{});
append_test dummy_judlg8gb(new sort_pair_test2<long>{});
append_test dummy_5egkzbcd(new sort_pair_test2<long long>{});

+ 42
- 0
tests/pointers_test.cpp View File

@ -0,0 +1,42 @@
#include "gp/utils/pointers.hpp"
#include "gp/utils/allocators/arena.hpp"
#include "test_scaffold.h"
#include "allocator.hpp"
#include <memory>
struct unique_ptr_test : public test_scaffold {
uint32_t seed;
unique_ptr_test() {
name = __FILE__ ":1";
}
virtual int run() {
std::unique_ptr<gp::array<char, 4096*4>> store = std::make_unique<gp::array<char, 4096*4>>();
gp::arena alloc{&*store->begin(), store->size()};
auto v = gp::unique_ptr<uint64_t>::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<gp::array<char, 4096*4>> store = std::make_unique<gp::array<char, 4096*4>>();
gp::arena alloc{&*store->begin(), store->size()};
auto v = gp::unique_ptr<std::string>::make(alloc, "1024");
return !(*(v->begin()) == '1' && v);
}
};
append_test dummy_aguhdff543(new unique_ptr2_test{});

+ 31
- 0
tests/tmp_manip_test.cpp View File

@ -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<uint32_t, uint64_t, int8_t>() != 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<uint32_t>() && gp::is_fixed_size<double>() && !gp::is_fixed_size<std::string>());
}
};
append_test dummy_sjuige443(new fixed_size_test{});

Loading…
Cancel
Save