diff --git a/src/v_pattern_matcher.cpp b/src/v_pattern_matcher.cpp index 3c37904..691e709 100644 --- a/src/v_pattern_matcher.cpp +++ b/src/v_pattern_matcher.cpp @@ -203,6 +203,14 @@ bool VPatternMatcher::configure(const DockProfile& profile, std::string& error) { return false; // Giữ bộ cũ; một profile áp nửa vời còn tệ hơn không áp. } + if (profile.pattern != PatternType::kV) + { + // `validate` chỉ kiểm profile có tự mâu thuẫn không, nó không biết ai đang cầm profile. Thiếu + // chỗ này thì một profile `pattern: arc` được bộ khớp chữ V nhận im lặng, rồi đi tìm hai cánh + // trên một mặt cong — dò mãi không ra, mà log thì báo là đang tìm chữ V. + error = std::string("VPatternMatcher was given pattern '") + toString(profile.pattern) + "'"; + return false; + } profile_ = profile; return true; } diff --git a/test/v_pattern_matcher_test.cpp b/test/v_pattern_matcher_test.cpp index 1b08e89..2d53477 100644 --- a/test/v_pattern_matcher_test.cpp +++ b/test/v_pattern_matcher_test.cpp @@ -607,6 +607,27 @@ DockProfile vTapeProfile() } } // namespace +TEST(VPatternMatcher, RefusesAProfileForADifferentPattern) +{ + // `DockProfile::validate` chỉ kiểm profile có tự mâu thuẫn không — nó không biết ai đang cầm. + // Thiếu cổng này thì `pattern: arc` được bộ khớp chữ V nhận im lặng rồi đi tìm hai cánh trên một + // mặt cong: dò mãi không ra, mà log lại báo đang tìm chữ V. Sai kiểu đó tốn cả buổi. + std::string error; + VPatternMatcher m; + + DockProfile p = vProfile(); + p.pattern = PatternType::kArc; + p.arc_radius = 0.40; + p.arc_radius_tolerance = 0.06; + p.arc_span = 2.0; + p.arc_min_span = 0.52; + p.arc_max_rms = 0.010; + p.min_arc_points = 8; + + EXPECT_FALSE(m.configure(p, error)); + EXPECT_NE(error.find("VPatternMatcher"), std::string::npos) << error; +} + TEST(VPatternMatcher, TapeConfirmsAPlateThatCarriesIt) { Rig rig(vTapeProfile());