@@ -27,6 +27,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828******************************************************************************/
2929
30+ #include < numeric>
31+
3032#include < gtest/gtest.h>
3133
3234#include < ocs2_core/constraint/StateConstraintCollection.h>
@@ -56,6 +58,37 @@ TEST(TestConstraintCollection, numberOfConstraints) {
5658 EXPECT_EQ (constraintCollection.getNumConstraints (0.0 ), addedConstraints);
5759}
5860
61+ TEST (TestConstraintCollection, termsSize) {
62+ ocs2::StateInputConstraintCollection constraintCollection;
63+
64+ // Initially we have zero constraints for all types
65+ auto termsSize = constraintCollection.getTermsSize (0.0 );
66+ EXPECT_EQ (termsSize.size (), 0 );
67+ EXPECT_EQ (std::accumulate (termsSize.begin (), termsSize.end (), 0 ), 0 );
68+
69+ // Add 2 Linear inequality constraint term, which has 2 constraints
70+ constraintCollection.add (" Constraint1" , std::make_unique<TestDummyConstraint>());
71+ constraintCollection.add (" Constraint2" , std::make_unique<TestDummyConstraint>());
72+ constraintCollection.add (" Constraint3" , std::make_unique<TestDummyConstraint>());
73+ auto & constraint1 = constraintCollection.get <TestDummyConstraint>(" Constraint1" );
74+ const size_t constraint1Size = constraint1.getNumConstraints (0.0 );
75+
76+ // Check the right constraint size
77+ termsSize = constraintCollection.getTermsSize (0.0 );
78+ EXPECT_EQ (termsSize.size (), 3 );
79+ if (termsSize.size () == 3 ) {
80+ EXPECT_EQ (termsSize[0 ], constraint1Size);
81+ EXPECT_EQ (termsSize[1 ], constraint1Size);
82+ EXPECT_EQ (termsSize[2 ], constraint1Size);
83+ }
84+
85+ // Deactivate constraint1
86+ constraint1.setActivity (false );
87+ termsSize = constraintCollection.getTermsSize (0.0 );
88+ EXPECT_EQ (termsSize.size (), 3 );
89+ EXPECT_EQ (std::accumulate (termsSize.begin (), termsSize.end (), 0 ), 2 * constraint1Size);
90+ }
91+
5992TEST (TestConstraintCollection, activatingConstraints) {
6093 ocs2::StateInputConstraintCollection constraintCollection;
6194
0 commit comments