@@ -3,6 +3,7 @@ package optim_test
3
3
import (
4
4
"fmt"
5
5
"github.com/MatProGo-dev/MatProInterface.go/optim"
6
+ "github.com/MatProGo-dev/SymbolicMath.go/symbolic"
6
7
"gonum.org/v1/gonum/mat"
7
8
"strings"
8
9
"testing"
@@ -1478,3 +1479,65 @@ func TestVarVector_Multiply8(t *testing.T) {
1478
1479
}
1479
1480
1480
1481
}
1482
+
1483
+ /*
1484
+ TestVarVector_ToSymbolic1
1485
+ Description:
1486
+
1487
+ Tests that the ToSymbolic() produces an error when the VarVector has one
1488
+ variable that is not well-defined.
1489
+ */
1490
+ func TestVarVector_ToSymbolic1 (t * testing.T ) {
1491
+ // Constants
1492
+ m := optim .NewModel ("TestVarVector_ToSymbolic1" )
1493
+ v1 := m .AddVariable ()
1494
+
1495
+ vv2 := optim.VarVector {}
1496
+ for i := 0 ; i < 10 ; i ++ {
1497
+ if i == 5 {
1498
+ vv2 .Elements = append (vv2 .Elements , optim.Variable {Lower : - 1 , Upper : - 2 })
1499
+ } else {
1500
+ vv2 .Elements = append (vv2 .Elements , v1 )
1501
+ }
1502
+ }
1503
+
1504
+ // Run ToSymbolic
1505
+ _ , err := vv2 .ToSymbolic ()
1506
+ if err == nil {
1507
+ t .Errorf ("expected error, but received none!" )
1508
+ } else {
1509
+ if ! strings .Contains (
1510
+ err .Error (),
1511
+ fmt .Sprintf ("element %v has an issue: %v" , 5 , "lower bound (-1) of variable is above upper bound (-2)." ),
1512
+ ) {
1513
+ t .Errorf ("unexpected error: %v" , err )
1514
+ }
1515
+ }
1516
+
1517
+ }
1518
+
1519
+ /*
1520
+ TestVarVector_ToSymbolic2
1521
+ Description:
1522
+
1523
+ Tests that the ToSymbolic() does not produce an error when the VarVector
1524
+ is well-defined. In addition, the output should be of type symbolic.VariableVector
1525
+ */
1526
+ func TestVarVector_ToSymbolic2 (t * testing.T ) {
1527
+ // Constants
1528
+ m := optim .NewModel ("TestVarVector_ToSymbolic2" )
1529
+ N := 10
1530
+
1531
+ vv2 := m .AddVariableVector (N )
1532
+
1533
+ // Run ToSymbolic
1534
+ symVv2 , err := vv2 .ToSymbolic ()
1535
+ if err != nil {
1536
+ t .Errorf ("unexpected error: %v" , err )
1537
+ }
1538
+
1539
+ _ , tf := symVv2 .(symbolic.VariableVector )
1540
+ if ! tf {
1541
+ t .Errorf ("expected output to be of type symbolic.VariableVector; received %T instead" , symVv2 )
1542
+ }
1543
+ }
0 commit comments