Skip to content

[Core] MultiVecId tests - #6287

Open
alxbilger wants to merge 4 commits into
sofa-framework:masterfrom
alxbilger:multivecidtests
Open

[Core] MultiVecId tests#6287
alxbilger wants to merge 4 commits into
sofa-framework:masterfrom
alxbilger:multivecidtests

Conversation

@alxbilger

@alxbilger alxbilger commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Unit tests mostly generated by Gemini 3.7 Flash.

I had to modify the MultiVecId class:

  • Checking the container is not empty in setId. Otherwise, an empty container would lead to hadIdMap returning true, but with an empty map.
  • Consistency in setId for the class TMultiVecId and its specialization for V_ALL: they both accept the same type std::set<State>. I decided to remove the most generic overload (template<class StateSet> void setId(const StateSet& states, const MyVecId& id)), because it causes ambiguity (and compilation errors) when calling setId on a BaseState* (not a const BaseState*).
  • unique() has been removed in C++20 (https://en.cppreference.com/cpp/memory/shared_ptr/unique), which proves that this code was not even called anywhere. But the unit tests call it.

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Sep 1, 2026
@fredroy

fredroy commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

alxbilger#12

fredroy and others added 3 commits September 2, 2026 08:37
* [Core] Unittest: pin MultiVecId's conversion and assignment contract

Most of TMultiVecId's API surface is a type system: which conversions are
implicit, which must stay explicit, and which must not exist at all. None
of that is reachable from a runtime EXPECT, so a refactor can silently
drop an overload and every existing test still passes.

Add static_asserts covering the three axes: access (write -> read only),
vtype widening (specific -> V_ALL implicit, V_ALL -> specific explicit),
and mutual exclusion of unrelated vtypes -- for construction and for
assignment alike.

* [Core] Unittest: check conversions carry and share the id map

AccessConversionCompatibility only converts multi-vec ids whose map is
empty, and only asserts on getDefaultId(). The converting constructor's
whole reason for existing -- handing the per-state id map to the target
without duplicating it -- was therefore untested.

Cover both directions: same vtype across access, and specific vtype to
V_ALL. Assert the contents and the storage identity; the no-copy part is
the design contract documented on BaseVecId in VecId.h, and it sits on a
path taken several times per solver iteration.

* [Core] Unittest: cover MultiVecId assignment

The suite had no assignment coverage at all -- every object was direct
initialized, so operator= appeared nowhere in the file.

Add two tests. The first pins the distinction between operator= and
assign(): assigning a TVecId replaces the default id and keeps the
per-state overrides, assign() drops them. MechanicalParams and
ConstraintParams depend on that difference, using assign() for their
TVecId setter overloads and operator= for the multi-vec ones.

The second covers narrowing a V_ALL id to a specific vtype, which is
explicit for construction but available as a plain assignment.

* [Core] Unittest: cover the copy-on-write branch of writeIdMap

Every setId() in the suite runs on an unshared map, so writeIdMap()'s
clone-when-shared branch was never taken. That is the branch the
shared_ptr::unique() replacement in this PR repairs -- on master the
V_ALL half of this test does not even compile -- so it should not stay
uncovered.

Copy a multi-vec id that owns a map, write through the copy, and check
the source is untouched and the storage has detached. Exercised on both
the primary template and the V_ALL specialisation.

* [Core] Unittest: assert the MultiVecId name format against literals

operator<< is implemented as `out << v.getName()`, so asserting the
stream against getName() compares the implementation to itself and would
pass whatever getName() returned.

Pin the format against literals instead. Use a single-state map so the
result does not depend on the id map's iteration order, which is by
BaseState address. Two shapes are covered: an entry whose vtype matches
the default id, printed by index, and one whose vtype differs, printed
by full name -- the latter branch of getName() had no coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: status to review To notify reviewers to review this pull-request pr: test PR adding test(s) in SOFA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants