Skip to content

[Core] Complete unit test suite for VecId - #6286

Open
alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:vecidtests
Open

[Core] Complete unit test suite for VecId#6286
alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:vecidtests

Conversation

@alxbilger

@alxbilger alxbilger commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Gemini 3.7 Flash generated the tests. I had to add the method getGroup in TStandardVec<V_ALL, vaccess>, otherwise it's ambiguous and it does not compile.

[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
EXPECT_EQ(VecId(VecType::V_MATDERIV, 10).getName(), "10(V_MATDERIV)");
}

TEST(TVecId, StreamOperator)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This compares the implementation to itself and would pass if getName were completely wrong. Hard-code the expected strings."

EXPECT_TRUE(coordWrite1 != genCoordDifferentIndex);
}

TEST(TVecId, Groups)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConstVecId are not tested and no V_ALL neither

VecCoordId coordTargetWrite;
coordTargetWrite = VecId(VecType::V_COORD, 20);
EXPECT_EQ(coordTargetWrite.getIndex(), 20u);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(coordTargetWrite.getType(), VecType::V_COORD);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This (and the 4 other) checks only the index on the V_ALL→specific path"
So we should check also the resulting type

ConstVecCoordId coordTargetRead;
coordTargetRead = VecId(VecType::V_COORD, 21); // Write generic to Read specific
EXPECT_EQ(coordTargetRead.getIndex(), 21u);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(coordTargetRead.getType(), VecType::V_COORD);


coordTargetRead = ConstVecId(VecType::V_COORD, 22); // Read generic to Read specific
EXPECT_EQ(coordTargetRead.getIndex(), 22u);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(coordTargetRead.getType(), VecType::V_COORD);


VecDerivId derivTargetWrite;
derivTargetWrite = VecId(VecType::V_DERIV, 23);
EXPECT_EQ(derivTargetWrite.getIndex(), 23u);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(derivTargetWrite.getIndex(), 23u);
EXPECT_EQ(derivTargetWrite.getIndex(), 23u);
EXPECT_EQ(derivTargetWrite.getType(), VecType::V_DERIV);


MatrixDerivId matDerivTargetWrite;
matDerivTargetWrite = VecId(VecType::V_MATDERIV, 24);
EXPECT_EQ(matDerivTargetWrite.getIndex(), 24u);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EQ(matDerivTargetWrite.getIndex(), 24u);
EXPECT_EQ(matDerivTargetWrite.getIndex(), 24u);
EXPECT_EQ(matDerivTargetWrite.getType(), VecType::V_MATDERIV);

constexpr VecId genWriteDeriv(VecType::V_DERIV, 9);
EXPECT_EQ(genWriteDeriv.getType(), VecType::V_DERIV);
EXPECT_EQ(genWriteDeriv.getIndex(), 9u);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
// Access: write-access ids convert implicitly to read-access ids.
static_assert(std::is_convertible_v<VecCoordId, ConstVecCoordId>);
static_assert(std::is_convertible_v<VecDerivId, ConstVecDerivId>);
static_assert(std::is_convertible_v<MatrixDerivId, ConstMatrixDerivId>);
// A specific id converts implicitly to the generic V_ALL id.
static_assert(std::is_convertible_v<VecCoordId, VecId>);
static_assert(std::is_convertible_v<VecCoordId, ConstVecId>);
// The reverse narrowing must stay explicit: constructible, never implicit.
static_assert(!std::is_convertible_v<VecId, VecCoordId>);
static_assert(std::is_constructible_v<VecCoordId, VecId>);
// Unrelated specific types never interconvert.
static_assert(!std::is_constructible_v<VecCoordId, VecDerivId>);
static_assert(!std::is_assignable_v<VecCoordId&, VecDerivId>);
// Assignment mirrors construction, including the V_ALL -> specific direction.
static_assert(std::is_assignable_v<VecCoordId&, VecId>);
static_assert(std::is_assignable_v<VecId&, VecCoordId>);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Could be somewhere else)
"The suite tests values but never the type system, which is what TVecId mostly is"

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