@@ -652,6 +652,53 @@ func TestScalarConstraint_LinearInequalityConstraintRepresentation5(t *testing.T
652652 sc .(symbolic.ScalarConstraint ).LinearInequalityConstraintRepresentation ()
653653}
654654
655+ /*
656+ TestScalarConstraint_LinearInequalityConstraintRepresentation6
657+ Description:
658+
659+ Tests the LinearInequalityConstraintRepresentation() method of a scalar
660+ constraint. This test verifies that the method correctly produces a vector with
661+ length 2 and a constant of value 2.1 when using a small cosntraint:
662+ x1 <= 2.1
663+ but when calculating the representation with respect to a vector of 2 variables.
664+ */
665+ func TestScalarConstraint_LinearInequalityConstraintRepresentation6 (t * testing.T ) {
666+ // Constants
667+ x := symbolic .NewVariableVector (2 )
668+ c2 := symbolic .K (2.1 )
669+
670+ // Create constraint
671+ sc := x .AtVec (0 ).LessEq (c2 )
672+
673+ // Verify that the constraint is linear
674+ if ! sc .IsLinear () {
675+ t .Errorf (
676+ "Expected sc to be linear; received %v" ,
677+ sc .IsLinear (),
678+ )
679+ }
680+
681+ // Get linear representation
682+ A , b := sc .(symbolic.ScalarConstraint ).LinearInequalityConstraintRepresentation (x )
683+
684+ // Verify that the vector is all ones
685+ if A .AtVec (0 ) != 1 {
686+ t .Errorf ("Expected A[0] to be 1; received %v" , A .AtVec (0 ))
687+ }
688+
689+ if A .AtVec (1 ) != 0 {
690+ t .Errorf ("Expected A[1] to be 0; received %v" , A .AtVec (1 ))
691+ }
692+
693+ // Verify that the constant is 2.5
694+ if b != 2.1 {
695+ t .Errorf (
696+ "Expected b to be 2.5; received %v" ,
697+ b ,
698+ )
699+ }
700+ }
701+
655702/*
656703TestScalarConstraint_LinearEqualityConstraintRepresentation1
657704Description:
@@ -847,3 +894,50 @@ func TestScalarConstraint_LinearEqualityConstraintRepresentation4(t *testing.T)
847894
848895 sc .(symbolic.ScalarConstraint ).LinearEqualityConstraintRepresentation ()
849896}
897+
898+ /*
899+ TestScalarConstraint_LinearEqualityConstraintRepresentation5
900+ Description:
901+
902+ Tests the LinearEqualityConstraintRepresentation() method of a scalar
903+ constraint. This test verifies that the method correctly produces a vector with
904+ length 2 and a constant of value 2.1 when using a small cosntraint:
905+ x1 = 2.1
906+ but when calculating the representation with respect to a vector of 2 variables.
907+ */
908+ func TestScalarConstraint_LinearEqualityConstraintRepresentation5 (t * testing.T ) {
909+ // Constants
910+ x := symbolic .NewVariableVector (2 )
911+ c2 := symbolic .K (2.1 )
912+
913+ // Create constraint
914+ sc := x .AtVec (0 ).Eq (c2 )
915+
916+ // Verify that the constraint is linear
917+ if ! sc .IsLinear () {
918+ t .Errorf (
919+ "Expected sc to be linear; received %v" ,
920+ sc .IsLinear (),
921+ )
922+ }
923+
924+ // Get linear representation
925+ A , b := sc .(symbolic.ScalarConstraint ).LinearEqualityConstraintRepresentation (x )
926+
927+ // Verify that the vector is all ones
928+ if A .AtVec (0 ) != 1 {
929+ t .Errorf ("Expected A[0] to be 1; received %v" , A .AtVec (0 ))
930+ }
931+
932+ if A .AtVec (1 ) != 0 {
933+ t .Errorf ("Expected A[1] to be 0; received %v" , A .AtVec (1 ))
934+ }
935+
936+ // Verify that the constant is 2.5
937+ if b != 2.1 {
938+ t .Errorf (
939+ "Expected b to be 2.5; received %v" ,
940+ b ,
941+ )
942+ }
943+ }
0 commit comments