From 4f0723f56ffdc12113de265b5a16d3260c2f2e83 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Fri, 31 Jul 2026 16:10:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E8=BF=87=E5=BC=AF?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=B5=8B=E8=AF=95=E6=9C=9F=E6=9C=9B=E5=80=BC?= =?UTF-8?q?=20+=20FreePathTests=20=E5=8A=A0=E5=85=A5csproj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 过弯检测 CornerTurnCheckHelper 代码正确(maxLength 均为正), 但 6 个测试期望值与公式不符(7e71387 改算法时测试未同步)。 已按公式修正测试:补充 maxLength 断言,调整长度阈值。 另修复 FreePathTests 一处断言(斜路径 forward/up 分量)。 并将 FreePathTests.cs 显式加入 UnitTests.csproj(此前未编译运行) --- NavisworksTransport.UnitTests.csproj | 1 + UnitTests/Core/CornerTurnCheckHelperTests.cs | 30 ++++++++++++++------ UnitTests/Core/FreePathTests.cs | 9 +++--- doc/design/2026/free-path-design.md | 5 +++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/NavisworksTransport.UnitTests.csproj b/NavisworksTransport.UnitTests.csproj index 9f5f4f1..0acd704 100644 --- a/NavisworksTransport.UnitTests.csproj +++ b/NavisworksTransport.UnitTests.csproj @@ -63,6 +63,7 @@ + diff --git a/UnitTests/Core/CornerTurnCheckHelperTests.cs b/UnitTests/Core/CornerTurnCheckHelperTests.cs index c9fd35a..89108d7 100644 --- a/UnitTests/Core/CornerTurnCheckHelperTests.cs +++ b/UnitTests/Core/CornerTurnCheckHelperTests.cs @@ -10,13 +10,17 @@ namespace NavisworksTransport.UnitTests.Core [TestMethod] public void LongEnoughForCorner_ShouldPass() { - Assert.IsTrue(CornerTurnCheckHelper.CanPass(6.5, 2.0, 4.8, 2.75, out _, out _)); + // maxLength ≈ 6.393,长度6.0 < 6.393 可通过 + Assert.IsTrue(CornerTurnCheckHelper.CanPass(6.0, 2.0, 4.8, 2.75, out _, out double max)); + Assert.AreEqual(6.3932, max, 1e-3); } [TestMethod] public void ModuleLongerThanRequired_ShouldPass() { - Assert.IsTrue(CornerTurnCheckHelper.CanPass(7.0, 0.5, 3.0, 2.5, out _, out _)); + // maxLength ≈ 6.765,长度6.5 < 6.765 可通过 + Assert.IsTrue(CornerTurnCheckHelper.CanPass(6.5, 0.5, 3.0, 2.5, out _, out double max)); + Assert.AreEqual(6.7652, max, 1e-3); } [TestMethod] @@ -50,25 +54,33 @@ namespace NavisworksTransport.UnitTests.Core [TestMethod] public void WideAndLongEnough_ShouldPass() { - Assert.IsTrue(CornerTurnCheckHelper.CanPass(3.0, 1.5, 2.0, 2.0, out _, out _)); + // maxLength ≈ 2.657,长度2.5 < 2.657 可通过 + Assert.IsTrue(CornerTurnCheckHelper.CanPass(2.5, 1.5, 2.0, 2.0, out _, out double max)); + Assert.AreEqual(2.6569, max, 1e-3); } [TestMethod] - public void WideAndTooShort_ShouldNotPass() + public void WideAndTooLong_ShouldNotPass() { - Assert.IsFalse(CornerTurnCheckHelper.CanPass(1.2, 1.5, 2.0, 2.0, out _, out _)); + // maxLength ≈ 2.657,长度3.0 > 2.657 不可通过 + Assert.IsFalse(CornerTurnCheckHelper.CanPass(3.0, 1.5, 2.0, 2.0, out _, out double max)); + Assert.AreEqual(2.6569, max, 1e-3); } [TestMethod] - public void NarrowLong_ShouldPass() + public void NarrowLongEnough_ShouldPass() { - Assert.IsTrue(CornerTurnCheckHelper.CanPass(4.0, 1.0, 2.0, 2.0, out _, out _)); + // maxLength ≈ 3.657,长度3.5 < 3.657 可通过 + Assert.IsTrue(CornerTurnCheckHelper.CanPass(3.5, 1.0, 2.0, 2.0, out _, out double max)); + Assert.AreEqual(3.6569, max, 1e-3); } [TestMethod] - public void NarrowTooShort_ShouldNotPass() + public void NarrowTooLong_ShouldNotPass() { - Assert.IsFalse(CornerTurnCheckHelper.CanPass(1.5, 1.0, 2.0, 2.0, out _, out _)); + // maxLength ≈ 3.657,长度4.0 > 3.657 不可通过 + Assert.IsFalse(CornerTurnCheckHelper.CanPass(4.0, 1.0, 2.0, 2.0, out _, out double max)); + Assert.AreEqual(3.6569, max, 1e-3); } } } diff --git a/UnitTests/Core/FreePathTests.cs b/UnitTests/Core/FreePathTests.cs index 4c3f945..8685da4 100644 --- a/UnitTests/Core/FreePathTests.cs +++ b/UnitTests/Core/FreePathTests.cs @@ -67,10 +67,11 @@ namespace NavisworksTransport.UnitTests.Core Assert.AreEqual(0.0, Vector3.Dot(forward, up), 1e-6); Assert.AreEqual(0.0, Vector3.Dot(forward, lateral), 1e-6); Assert.AreEqual(0.0, Vector3.Dot(lateral, up), 1e-6); - // 切线方向(应为 X 方向主导) - Assert.IsTrue(Vector3.Dot(forward, Vector3.UnitX) > 0.99f); - // up 接近世界 Z(投影正交化) - Assert.IsTrue(Vector3.Dot(up, Vector3.UnitZ) > 0.95f); + // 切线方向沿X上升((2,0,1)/√5 ≈ (0.894,0,0.447),X为主) + Assert.IsTrue(Vector3.Dot(forward, Vector3.UnitX) > 0.80f); + // up 为世界Z在 forward 上的投影正交化,随坡度倾斜约26.6°, + // Dot(up, Z) ≈ cos(26.6°) ≈ 0.894,仍以上方为主 + Assert.IsTrue(Vector3.Dot(up, Vector3.UnitZ) > 0.80f); } [TestMethod] diff --git a/doc/design/2026/free-path-design.md b/doc/design/2026/free-path-design.md index e4f171f..d6f6657 100644 --- a/doc/design/2026/free-path-design.md +++ b/doc/design/2026/free-path-design.md @@ -132,6 +132,9 @@ framePosition 即物体中心,现有碰撞盒计算直接正确(无需改动 | 8 | 补单测(中心对齐 + 姿态 + 多点) | ✅ | 新增 FreePathTests(6个) | | 9 | 编译 + 单测 + 部署 + 手动验证 | 🔄 | 需部署后手动验证 | -> ⚠️ 已知 pre-existing 问题:`CornerTurnCheckHelperTests` 6个测试失败,与自由路径无关,需另行排查 +> ✅ 附带修复:`CornerTurnCheckHelperTests` 6个 pre-existing 失败 +> - 根因:代码正确,测试期望值与公式不符(`7e71387` 改算法时测试未同步) +> - 已修正测试期望值 + 补 maxLength 断言 +> - 另将 `FreePathTests.cs` 显式加入 UnitTests.csproj(此前未编译) > 进度图例:☐ 未开始 / 🔄 进行中 / ✅ 完成