summaryrefslogtreecommitdiff
path: root/modules/codec/tests/math.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/codec/tests/math.cpp')
-rw-r--r--modules/codec/tests/math.cpp38
1 files changed, 32 insertions, 6 deletions
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<sch::Vector<sch::Float64, 2u>> a;
@@ -84,14 +84,40 @@ SAW_TEST("Math/Tensor Mult Scalar"){
a.at({{0u}}) = 2.0;
a.at({{1u}}) = 1.0;
}
- data<sch::Vector<sch::Float64, 2u>> 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<sch::Vector<sch::Float64, 2u>> 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<sch::Vector<sch::Float64, 2u>> 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()) );
}
}