From 5b822e1422ed808de9144da8ed38037b17dd0b65 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 23 Sep 2025 22:29:01 +0200 Subject: Added tests for dot product --- modules/codec/tests/math.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'modules/codec/tests') diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp index cc371dd..6f60e9c 100644 --- a/modules/codec/tests/math.cpp +++ b/modules/codec/tests/math.cpp @@ -76,7 +76,7 @@ SAW_TEST("Math/Dot"){ SAW_EXPECT(c.at({}).get() == 3.0, std::string{"Unexpected value for dot product "} + std::to_string(c.at({}).get()) ); } -SAW_TEST("Math/Tensor Mult Scalar"){ +SAW_TEST("Math/Dot Self"){ using namespace saw; data> a; @@ -84,14 +84,40 @@ SAW_TEST("Math/Tensor Mult Scalar"){ a.at({{0u}}) = 2.0; a.at({{1u}}) = 1.0; } - data> b; + + auto c = math::dot(a,a); + + SAW_EXPECT(c.at({}).get() == 5.0, std::string{"Unexpected value for dot product "} + std::to_string(c.at({}).get()) ); +} + +SAW_TEST("Math/Dot and Sqrt"){ + using namespace saw; + + data> a; { - b.at({{0u}}) = -1.0; - b.at({{1u}}) = 5.0; + a.at({{0u}}) = 3.0; + a.at({{1u}}) = 4.0; } - auto c = math::dot(a,b); + auto c = math::dot(a,a); - SAW_EXPECT(c.at({}).get() == 3.0, std::string{"Unexpected value for dot product "} + std::to_string(c.at({}).get()) ); + auto d = math::sqrt(c); + + SAW_EXPECT(d.at({}).get() == 5.0, std::string{"Unexpected value for dot + sqrt "} + std::to_string(d.at({}).get()) ); +} + +SAW_TEST("Math/Normalize"){ + using namespace saw; + + data> a; + { + a.at({{0u}}) = 5.0; + a.at({{1u}}) = 0.0; + } + + auto c = math::normalize(a); + + SAW_EXPECT(c.at({{0u}}).get() == 1.0, std::string{"Unexpected value for dot + sqrt "} + std::to_string(c.at({{0u}}).get()) ); + SAW_EXPECT(c.at({{1u}}).get() == 0.0, std::string{"Unexpected value for dot + sqrt "} + std::to_string(c.at({{1u}}).get()) ); } } -- cgit v1.2.3