fix(integrate): sort boundary edges as pairs

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-28 09:34:28 +02:00
parent 32e2c1efab
commit a4000c0a82
3 changed files with 49 additions and 3 deletions
+28
View File
@@ -434,6 +434,34 @@ func TestTriangleMesh2DBoundaryEdges(t *testing.T) {
}
}
// TestTriangleMesh2DBoundaryEdgesAreMeshEdges pins the pair contract of
// BoundaryEdges: every returned pair must be an edge the mesh actually
// carries, and the pairs must come out sorted, which a sort of the flat
// index list cannot deliver (it interleaves unrelated endpoints).
func TestTriangleMesh2DBoundaryEdgesAreMeshEdges(t *testing.T) {
mesh, err := GridTriangleMesh2D(0, 0, 1, 1, 1, 1)
if err != nil {
t.Fatalf("GridTriangleMesh2D: %v", err)
}
edges := mesh.BoundaryEdges()
// The square's four sides: (0,1), (0,2), (1,3), (2,3) in sorted
// pair order.
want := []int{0, 1, 0, 2, 1, 3, 2, 3}
if len(edges) != len(want) {
t.Fatalf("boundary edge count %d, want %d", len(edges)/2, len(want)/2)
}
for p := 0; p < len(edges); p += 2 {
if edges[p] > edges[p+1] {
t.Fatalf("edge [%d,%d] is not sorted as a pair", edges[p], edges[p+1])
}
}
for p := range len(want) {
if edges[p] != want[p] {
t.Fatalf("boundary edges %v, want %v", edges, want)
}
}
}
// TestSolvePoissonFEM2DDuplicateDirichletNode pins the documented rule
// for a node listed more than once: the last value is the prescribed
// one and the node enters the assembled system exactly once, so the