[Core] Complete unit test suite for VecId - #6286
Conversation
| EXPECT_EQ(VecId(VecType::V_MATDERIV, 10).getName(), "10(V_MATDERIV)"); | ||
| } | ||
|
|
||
| TEST(TVecId, StreamOperator) |
There was a problem hiding this comment.
"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) |
There was a problem hiding this comment.
ConstVecId are not tested and no V_ALL neither
| VecCoordId coordTargetWrite; | ||
| coordTargetWrite = VecId(VecType::V_COORD, 20); | ||
| EXPECT_EQ(coordTargetWrite.getIndex(), 20u); | ||
|
|
There was a problem hiding this comment.
| EXPECT_EQ(coordTargetWrite.getType(), VecType::V_COORD); | |
There was a problem hiding this comment.
"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); | ||
|
|
There was a problem hiding this comment.
| EXPECT_EQ(coordTargetRead.getType(), VecType::V_COORD); | |
|
|
||
| coordTargetRead = ConstVecId(VecType::V_COORD, 22); // Read generic to Read specific | ||
| EXPECT_EQ(coordTargetRead.getIndex(), 22u); | ||
|
|
There was a problem hiding this comment.
| EXPECT_EQ(coordTargetRead.getType(), VecType::V_COORD); |
|
|
||
| VecDerivId derivTargetWrite; | ||
| derivTargetWrite = VecId(VecType::V_DERIV, 23); | ||
| EXPECT_EQ(derivTargetWrite.getIndex(), 23u); |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
| 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); | ||
| } |
There was a problem hiding this comment.
| } | |
| // 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>); | |
| } |
There was a problem hiding this comment.
(Could be somewhere else)
"The suite tests values but never the type system, which is what TVecId mostly is"
Gemini 3.7 Flash generated the tests. I had to add the method
getGroupinTStandardVec<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