-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit testing framework and tests for existing code (and assorted …
…fixes and breaking API changes) (#23) * wip: add catch2 and 1 == 1 test case * chore: specify minimum meson version * chore: don't commit catch2 source * wip: add matrix multiplication test * fix: specify visibility for all symbols * fix: add include guard * feat: add cpp visibility macros to logger * fix: actually define the visbility macro when building shared lib * fix: add missing include directives i sure hope nothing else is missing and nothing else was messed up by the merge * wip: refactor meson build * refactor: move logger.hpp to include directory to enable building * wip: refactor meson build but on this branch * fix: remove non-existent directory from includes * fix: fix some memory allocation and constructor whoopsies in matrix and vector classes * wip: test seems to pass after refactor * feat!: add getter and test for matrix * feat!: make getter and setter for matrix throw when oob * refactor: use bdd-style macros for testing matrix getters and setters * tests: add tests for activation functions * test: test jml::Vector * feat: enable use of any type in iterator overload for add_testing_data * feat: add testing data getter * fix: move model implementation around so it builds and links * feat: add copy constructor to Vector * tests: test Model * docs: add information about testing * fix: add missing includes for tuple * ci: upload testlog as artifact * ci: change artifact name * docs: fix md link in readme
- Loading branch information
Showing
19 changed files
with
581 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "model.hpp" | ||
|
||
namespace jml { | ||
|
||
template<typename Iter> | ||
void Model::add_testing_data (Iter inb, Iter ine, Iter otb, Iter ote) { | ||
testing_data_inputs .insert(std::end(testing_data_inputs), inb, ine); | ||
testing_data_outputs.insert(std::end(testing_data_outputs), otb, ote); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
project('jml', 'cpp', | ||
default_options: ['cpp_std=c++14']) | ||
default_options: ['cpp_std=c++14'], | ||
meson_version: '>=1.2.0') | ||
|
||
catch2_proj = subproject('catch2', default_options: {'tests': false}) | ||
catch2_dep = catch2_proj.get_variable('catch2_with_main_dep') | ||
|
||
subdir('core') | ||
|
||
subdir('tests') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[wrap-file] | ||
directory = Catch2-3.4.0 | ||
source_url = https://github.com/catchorg/Catch2/archive/v3.4.0.tar.gz | ||
source_filename = Catch2-3.4.0.tar.gz | ||
source_hash = 122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb | ||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.4.0-1/Catch2-3.4.0.tar.gz | ||
wrapdb_version = 3.4.0-1 | ||
|
||
[provide] | ||
catch2 = catch2_dep | ||
catch2-with-main = catch2_with_main_dep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "catch2/catch_test_macros.hpp" | ||
#include "catch2/matchers/catch_matchers.hpp" | ||
#include "catch2/matchers/catch_matchers_floating_point.hpp" | ||
#include "jml/math/activation_functions.hpp" | ||
|
||
TEST_CASE("FastSigmoid function", "[activation_function]") { | ||
jml::FastSigmoid act; | ||
|
||
// FIXME: I don't know what mathematically significant values to check so here's some random ones | ||
// FIXME: FastSigmoid impl appears to have forgotten the constant offset | ||
REQUIRE_THAT(act.f(-1), Catch::Matchers::WithinRel(-0.25, 0.00001)); | ||
REQUIRE_THAT(act.f(0), Catch::Matchers::WithinRel(0, 0.00001)); | ||
REQUIRE_THAT(act.f(1), Catch::Matchers::WithinRel(0.25, 0.00001)); | ||
} | ||
|
||
TEST_CASE("Sigmoid activation function", "[activation_function]") { | ||
jml::Sigmoid act; | ||
|
||
REQUIRE_THAT(act.f(-1), Catch::Matchers::WithinRel(0.2689414, 0.00001)); | ||
REQUIRE_THAT(act.f(0), Catch::Matchers::WithinRel(0.5, 0.00001)); | ||
REQUIRE_THAT(act.f(1), Catch::Matchers::WithinRel(0.7310586, 0.00001)); | ||
|
||
REQUIRE_THAT(act.df(-1), Catch::Matchers::WithinRel(0.1966119, 0.00001)); | ||
REQUIRE_THAT(act.df(0), Catch::Matchers::WithinRel(0.25, 0.00001)); | ||
REQUIRE_THAT(act.df(1), Catch::Matchers::WithinRel(0.1966119, 0.00001)); | ||
} | ||
|
||
TEST_CASE("ReLU activation function", "[activation_function]") { | ||
jml::ReLU act; | ||
|
||
REQUIRE(act.f(-1) == 0); | ||
REQUIRE(act.f(0) == 0); | ||
REQUIRE(act.f(1) == 1); | ||
|
||
REQUIRE(act.df(-1) == 0); | ||
// REQUIRE(act.df(0) == 0); FIXME: is this UB? | ||
REQUIRE(act.df(1) == 1); | ||
} | ||
|
||
TEST_CASE("LeakyReLU activation function", "[activation_function]") { | ||
jml::LeakyReLU act; | ||
|
||
REQUIRE_THAT(act.f(-1), Catch::Matchers::WithinRel(-0.01, 0.00001)); | ||
REQUIRE(act.f(0) == 0); | ||
REQUIRE(act.f(1) == 1); | ||
|
||
REQUIRE_THAT(act.df(-1), Catch::Matchers::WithinRel(0.01, 0.00001)); | ||
// REQUIRE(act.df(0) == 0); FIXME: is this UB? | ||
REQUIRE(act.df(1) == 1); | ||
} | ||
|
||
TEST_CASE("LeakyReLU activation function with custom leak", "[activation_function]") { | ||
jml::LeakyReLU act(0.0001); | ||
|
||
// TODO: is it necessary to check function values? | ||
|
||
REQUIRE_THAT(act.df(-1), Catch::Matchers::WithinRel(0.0001, 0.00001)); | ||
REQUIRE(act.df(1) == 1); | ||
} |
Oops, something went wrong.