Skip to content

Commit f8b8c23

Browse files
author
Kwesi Rutledge
committed
Adding a test for when the left hand side of the constraint is nonlinear + makes sure that it panics
1 parent 61933f8 commit f8b8c23

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

testing/symbolic/vector_constraint_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,44 @@ func TestVectorConstraint_LinearEqualityConstraintRepresentation4(t *testing.T)
440440
)
441441
}
442442
}
443+
444+
/*
445+
TestVectorConstraint_LinearInequalityConstraintRepresentation5
446+
Description:
447+
448+
This function tests that the LinearInequalityConstraintRepresentation method
449+
properly panics if the left hand side is not linear.
450+
*/
451+
func TestVectorConstraint_LinearInequalityConstraintRepresentation5(t *testing.T) {
452+
// Constants
453+
N := 7
454+
right := symbolic.VecDenseToKVector(symbolic.OnesVector(N))
455+
x := symbolic.NewVariableVector(N)
456+
left := x.Plus(x.Transpose().Multiply(x))
457+
vc := left.GreaterEq(right).(symbolic.VectorConstraint)
458+
459+
// Test
460+
defer func() {
461+
r := recover()
462+
if r == nil {
463+
t.Errorf(
464+
"Expected vc.LinearInequalityConstraintRepresentation() to panic; received nil",
465+
)
466+
}
467+
468+
rAsError := r.(error)
469+
expectedError := smErrors.LinearExpressionRequiredError{
470+
Operation: "LinearInequalityConstraintRepresentation",
471+
Expression: vc.Left(),
472+
}
473+
if rAsError.Error() != expectedError.Error() {
474+
t.Errorf(
475+
"Expected vc.LinearInequalityConstraintRepresentation() to panic with error \"%v\"; received \"%v\"",
476+
expectedError.Error(),
477+
rAsError.Error(),
478+
)
479+
}
480+
}()
481+
482+
vc.LinearInequalityConstraintRepresentation()
483+
}

0 commit comments

Comments
 (0)