diff --git a/tests/core/math/test_losses.cpp b/tests/core/math/test_losses.cpp new file mode 100644 index 0000000..922a7dd --- /dev/null +++ b/tests/core/math/test_losses.cpp @@ -0,0 +1,17 @@ +#include "catch2/catch_test_macros.hpp" +#include +#include + +SCENARIO("Loss can be calculated from two vectors") { + GIVEN("Two vectors of the same size") { + jml::Vector vec1(3), vec2(3); + vec1.set_entry(0, 1.0); + vec1.set_entry(1, 2.0); + vec1.set_entry(2, 3.0); + vec2.set_entry(0, 4.0); + vec2.set_entry(1, 2.0); + vec2.set_entry(2,-2.0); + auto loss = jml::l2lf(vec1, vec2); + REQUIRE(loss == 5.0); + } +} diff --git a/tests/meson.build b/tests/meson.build index 5d2749f..c5d8c0c 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -2,6 +2,7 @@ core_test_sources = [ 'core/math/test_matrix.cpp', 'core/math/test_vector.cpp', 'core/math/test_activation_functions.cpp', + 'core/math/test_losses.cpp', 'core/test_model.cpp', ]