Skip to content

Commit

Permalink
Added More Tests for VarVectorTranspose
Browse files Browse the repository at this point in the history
  • Loading branch information
kwesiRutledge committed Feb 28, 2024
1 parent c737127 commit 9184377
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions testing/optim/var_vector_transpose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1907,3 +1907,127 @@ func TestVarVectorTranspose_Multiply14(t *testing.T) {
}

}

/*
TestVarVectorTranspose_Check1
Description:
Tests the Check method for a VarVectorTranspose.
When there is an incorrectly initialized variable in one of the elements,
then this should throw an error.
*/
func TestVarVectorTranspose_Check1(t *testing.T) {
// Constants
m := optim.NewModel("VarVectorTranspose_Check1")
N := 4

// Create VarVector
vv0 := optim.VarVectorTranspose{}
for ii := 0; ii < N; ii++ {
if ii == 2 {
vv0.Elements = append(vv0.Elements, optim.Variable{Lower: -1.0, Upper: -2.0})
} else {
vv0.Elements = append(vv0.Elements, m.AddVariable())
}
}

// Check
err := vv0.Check()
if err == nil {
t.Errorf("No error was thrown, but we expected one!")
} else {
if !strings.Contains(
err.Error(),
"element 2 has an issue:",
) {
t.Errorf("Unexpected error: %v", err)
}
}

}

/*
TestVarVectorTranspose_Check2
Description:
Tests the Check method for a VarVectorTranspose.
For a properly initialized VarVectorTranspose, this should not throw an error.
*/
func TestVarVectorTranspose_Check2(t *testing.T) {
// Constants
m := optim.NewModel("VarVectorTranspose_Check2")
N := 4

// Create VarVector
vvt0 := m.AddVariableVector(N).Transpose().(optim.VarVectorTranspose)

// Check
err := vvt0.Check()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

/*
TestVarVectorTranspose_ToSymbolic1
Description:
Tests the ToSymbolic method for a VarVectorTranspose
that is not well-defined. This should throw an error.
*/
func TestVarVectorTranspose_ToSymbolic1(t *testing.T) {
// Constants
m := optim.NewModel("VarVectorTranspose_ToSymbolic1")
N := 4

// Create VarVector
vv0 := optim.VarVectorTranspose{}
for ii := 0; ii < N; ii++ {
if ii == 2 {
vv0.Elements = append(vv0.Elements, optim.Variable{Lower: -1.0, Upper: -2.0})
} else {
vv0.Elements = append(vv0.Elements, m.AddVariable())
}
}

// Check
_, err := vv0.ToSymbolic()
if err == nil {
t.Errorf("No error was thrown, but we expected one!")
} else {
if !strings.Contains(
err.Error(),
"element 2 has an issue:",
) {
t.Errorf("Unexpected error: %v", err)
}
}
}

/*
TestVarVectorTranspose_ToSymbolic2
Description:
Tests the ToSymbolic method for a VarVectorTranspose
that is well-defined. The result should not produce
an error and should be of the type symbolic.VariableMatrix.
*/
func TestVarVectorTranspose_ToSymbolic2(t *testing.T) {
// Constants
m := optim.NewModel("VarVectorTranspose_ToSymbolic2")
N := 4

// Create VarVector
vvt0 := m.AddVariableVector(N).Transpose().(optim.VarVectorTranspose)

// Check
sym1, err := vvt0.ToSymbolic()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}

_, tf := sym1.(symbolic.VariableMatrix)
if !tf {
t.Errorf("Expected type symbolic.VariableMatrix; received type %T", sym1)
}
}

0 comments on commit 9184377

Please sign in to comment.