Skip to content

Commit a03620c

Browse files
authored
Merge pull request #121 from luadebug/try
Run unit tests for WASM
2 parents 1499ac3 + 4a8e7e8 commit a03620c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@ jobs:
506506
cmake-build/build/${{ matrix.preset }}/**/*.log
507507
${{ env.VCPKG_ROOT }}/buildtrees/**/*.log
508508
509+
- name: Setup Node.js
510+
uses: actions/setup-node@v4
511+
with:
512+
node-version: '20'
513+
514+
- name: Run WASM Unit Tests
515+
run: node out/Release/unit_tests.js
516+
509517
##############################################################################
510518
# 8) Windows MSYS2 MinGW – GCC / Ninja
511519
##############################################################################

include/omath/linear_algebra/vector3.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ namespace omath
233233
return Angle<float, 0.f, 180.f, AngleFlags::Clamped>::from_radians(std::acos(dot(other) / bottom));
234234
}
235235

236-
[[nodiscard]] bool is_perpendicular(const Vector3& other) const noexcept
236+
[[nodiscard]] bool is_perpendicular(const Vector3& other, Type epsilon = static_cast<Type>(0.0001)) const noexcept
237237
{
238238
if (const auto angle = angle_between(other))
239-
return angle->as_degrees() == static_cast<Type>(90);
239+
return std::abs(angle->as_degrees() - static_cast<Type>(90)) <= epsilon;
240240

241241
return false;
242242
}

tests/general/unit_test_vector3.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ TEST_F(UnitTestVector3, AsTuple)
390390
// Test AsTuple method
391391
TEST_F(UnitTestVector3, AngleBeatween)
392392
{
393-
EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).angle_between({1, 0 ,0}).value().as_degrees(), 90.0f);
394-
EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).angle_between({0.0f, 0.0f, 1.0f}).value().as_degrees(), 0.0f);
393+
EXPECT_NEAR(Vector3(0.0f, 0.0f, 1.0f).angle_between({1, 0, 0}).value().as_degrees(),
394+
90.0f, 0.001f);
395+
EXPECT_NEAR(Vector3(0.0f, 0.0f, 1.0f).angle_between({0.0f, 0.0f, 1.0f}).value().as_degrees(),
396+
0.0f, 0.001f);
395397
EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).angle_between({0.0f, 0.0f, 1.0f}).has_value());
396398
}
397399

0 commit comments

Comments
 (0)