ci / ubuntu-latest / clang (push) Failing after 1m31s
ci / ubuntu-latest / gcc (push) Failing after 32s
ci / macos-latest / apple-clang (push) Canceled after 0s
ci / windows-latest / mingw (push) Canceled after 0s
ci / windows-latest / msvc (push) Canceled after 0s
- r1:全库标识符 gcs→vdcs(目录/文件 git mv、命名空间/C ABI/CMake target/文档, 五轮正则 12000+ 处;204/204 编译零警告) - c3:FreeCAD SketcherTests TestSketcherSolver 11 语义类场景 JSON 转换写盘 tests/corpus/scenes/(LGPL 上游数值派生逐件标注) - c4:回放器 vdcs_corpus_replay 联调 11/11,4 项修正——DistanceX/Y 参数序 (引擎残差 xb−xa−v)、add_axis 轴向反转、TangentAtPoint 放宽 Arc2D、 场景 04 断言语义对齐原测试(ExpressionEngine 清空等价由单测覆盖) - c5:ctest 41/41 全绿;33 号真实语料验证报告(转换映射定案 + 引擎语义 确认清单);07 对标矩阵 v1.3(词表 29→31 补 CircleDistance/ CircleLineDistance 保侧距离族);31 号进度 P6 收官
145 lines
4.9 KiB
C++
145 lines
4.9 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "vdcs/core/constraint_graph.h"
|
|
#include "vdcs/model/model.h"
|
|
|
|
using vdcs::ConstraintGraph;
|
|
using vdcs::Model;
|
|
|
|
namespace {
|
|
|
|
/// 两点 + 固定 + 距离(单分量,2 实体 2 约束)
|
|
struct ChainModel {
|
|
Model model;
|
|
vdcs::Uid pa;
|
|
vdcs::Uid pb;
|
|
vdcs::Uid pc;
|
|
vdcs::Uid d_ab;
|
|
vdcs::Uid c_bc;
|
|
};
|
|
|
|
/// 链式模型:A --Distance-- B --Coincident-- C(单分量 3 实体 2 约束)
|
|
ChainModel BuildChain() {
|
|
ChainModel t;
|
|
t.pa = t.model.AddPoint2D("A", 0.0, 0.0).Value();
|
|
t.pb = t.model.AddPoint2D("B", 5.0, 0.0).Value();
|
|
t.pc = t.model.AddPoint2D("C", 5.0, 1.0).Value();
|
|
t.d_ab = t.model.AddDistance2D("D_AB", t.pa, t.pb, 5.0).Value();
|
|
t.c_bc = t.model.AddCoincident2D("C_BC", t.pb, t.pc).Value();
|
|
return t;
|
|
}
|
|
|
|
bool Contains(const std::vector<vdcs::Uid>& list, vdcs::Uid uid) {
|
|
return std::find(list.begin(), list.end(), uid) != list.end();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(ConstraintGraphTest, Adjacency) {
|
|
ChainModel t = BuildChain();
|
|
ConstraintGraph g = ConstraintGraph::Build(t.model);
|
|
|
|
EXPECT_EQ(g.EntityCount(), 3);
|
|
EXPECT_EQ(g.ConstraintCount(), 2);
|
|
EXPECT_TRUE(g.HasEntity(t.pa));
|
|
EXPECT_TRUE(g.HasConstraint(t.d_ab));
|
|
EXPECT_FALSE(g.HasEntity(99999u));
|
|
EXPECT_FALSE(g.HasConstraint(99999u));
|
|
|
|
// 约束 -> 实体(声明顺序)
|
|
const auto& ab_entities = g.EntitiesOfConstraint(t.d_ab);
|
|
ASSERT_EQ(ab_entities.size(), 2u);
|
|
EXPECT_EQ(ab_entities[0], t.pa);
|
|
EXPECT_EQ(ab_entities[1], t.pb);
|
|
|
|
// 实体 -> 约束:B 被 Distance 与 Coincident 同时引用
|
|
EXPECT_EQ(g.Degree(t.pa), 1);
|
|
EXPECT_EQ(g.Degree(t.pb), 2);
|
|
EXPECT_EQ(g.Degree(t.pc), 1);
|
|
const auto& b_constraints = g.ConstraintsOfEntity(t.pb);
|
|
EXPECT_TRUE(Contains(b_constraints, t.d_ab));
|
|
EXPECT_TRUE(Contains(b_constraints, t.c_bc));
|
|
}
|
|
|
|
TEST(ConstraintGraphTest, SharedEntitySingleComponent) {
|
|
ChainModel t = BuildChain();
|
|
ConstraintGraph g = ConstraintGraph::Build(t.model);
|
|
|
|
ASSERT_EQ(g.ComponentCount(), 1);
|
|
const auto& comp = g.ComponentAt(0);
|
|
EXPECT_EQ(comp.entities.size(), 3u);
|
|
EXPECT_EQ(comp.constraints.size(), 2u);
|
|
// 所有节点同属一个分量
|
|
EXPECT_EQ(g.ComponentOfEntity(t.pa), 0);
|
|
EXPECT_EQ(g.ComponentOfEntity(t.pb), 0);
|
|
EXPECT_EQ(g.ComponentOfEntity(t.pc), 0);
|
|
EXPECT_EQ(g.ComponentOfConstraint(t.d_ab), 0);
|
|
EXPECT_EQ(g.ComponentOfConstraint(t.c_bc), 0);
|
|
}
|
|
|
|
TEST(ConstraintGraphTest, SeparateComponents) {
|
|
Model model;
|
|
auto p1 = model.AddPoint2D("P1", 0.0, 0.0).Value();
|
|
auto p2 = model.AddPoint2D("P2", 3.0, 0.0).Value();
|
|
auto p3 = model.AddPoint2D("P3", 10.0, 0.0).Value();
|
|
auto p4 = model.AddPoint2D("P4", 13.0, 0.0).Value();
|
|
auto lone = model.AddPoint2D("LONE", 100.0, 100.0).Value();
|
|
(void)model.AddDistance2D("D1", p1, p2, 3.0);
|
|
(void)model.AddDistance2D("D2", p3, p4, 3.0);
|
|
|
|
ConstraintGraph g = ConstraintGraph::Build(model);
|
|
// 两个连通对 + 一个孤立实体 = 3 个分量
|
|
ASSERT_EQ(g.ComponentCount(), 3);
|
|
EXPECT_EQ(g.ComponentOfEntity(p1), g.ComponentOfEntity(p2));
|
|
EXPECT_EQ(g.ComponentOfEntity(p3), g.ComponentOfEntity(p4));
|
|
EXPECT_NE(g.ComponentOfEntity(p1), g.ComponentOfEntity(p3));
|
|
EXPECT_NE(g.ComponentOfEntity(p1), g.ComponentOfEntity(lone));
|
|
|
|
// 孤立实体:度 0,所在分量只有它自己
|
|
EXPECT_EQ(g.Degree(lone), 0);
|
|
const auto& lone_comp = g.ComponentAt(g.ComponentOfEntity(lone));
|
|
EXPECT_EQ(lone_comp.entities.size(), 1u);
|
|
EXPECT_EQ(lone_comp.constraints.size(), 0u);
|
|
}
|
|
|
|
TEST(ConstraintGraphTest, CrossEntityConstraintMerges) {
|
|
// Tangent(线-圆) 跨接两个实体 → 同一分量
|
|
Model model;
|
|
auto p1 = model.AddPoint2D("P1", 0.0, 0.0).Value();
|
|
auto p2 = model.AddPoint2D("P2", 3.0, 0.0).Value();
|
|
auto l = model.AddLine2D("L", 0.0, 2.0).Value();
|
|
auto c = model.AddCircle2D("C", 3.0, 7.0, 1.0).Value();
|
|
(void)model.AddDistance2D("D1", p1, p2, 3.0);
|
|
(void)model.AddTangent2D("TAN", l, c);
|
|
|
|
ConstraintGraph g = ConstraintGraph::Build(model);
|
|
ASSERT_EQ(g.ComponentCount(), 2);
|
|
const auto& comp = g.ComponentAt(g.ComponentOfConstraint(
|
|
model.Constraints().back()->Id()));
|
|
EXPECT_EQ(comp.entities.size(), 2u); // 线 + 圆
|
|
EXPECT_EQ(comp.constraints.size(), 1u);
|
|
}
|
|
|
|
TEST(ConstraintGraphTest, UnknownUidSafe) {
|
|
ChainModel t = BuildChain();
|
|
ConstraintGraph g = ConstraintGraph::Build(t.model);
|
|
|
|
EXPECT_TRUE(g.EntitiesOfConstraint(99999u).empty());
|
|
EXPECT_TRUE(g.ConstraintsOfEntity(99999u).empty());
|
|
EXPECT_EQ(g.Degree(99999u), -1);
|
|
EXPECT_EQ(g.ComponentOfEntity(99999u), -1);
|
|
EXPECT_EQ(g.ComponentOfConstraint(99999u), -1);
|
|
}
|
|
|
|
TEST(ConstraintGraphTest, EmptyModel) {
|
|
Model model;
|
|
ConstraintGraph g = ConstraintGraph::Build(model);
|
|
EXPECT_EQ(g.EntityCount(), 0);
|
|
EXPECT_EQ(g.ConstraintCount(), 0);
|
|
EXPECT_EQ(g.ComponentCount(), 0);
|
|
EXPECT_TRUE(g.Entities().empty());
|
|
EXPECT_TRUE(g.Constraints().empty());
|
|
}
|