@@ -46,3 +46,148 @@ func TestMatrixExpression_ToMatrixExpression1(t *testing.T) {
46
46
}
47
47
}
48
48
}
49
+
50
+ /*
51
+ TestMatrixExpression_ConcretizeMatrixExpression1
52
+ Description:
53
+
54
+ Tests the conversion of a slice of slices of constants (K) to a KMatrix.
55
+ */
56
+ func TestMatrixExpression_ConcretizeMatrixExpression1 (t * testing.T ) {
57
+ // Setup
58
+ x := [][]symbolic.ScalarExpression {
59
+ {symbolic .K (1.0 ), symbolic .K (2 ), symbolic .K (3 )},
60
+ {symbolic .K (4 ), symbolic .K (5 ), symbolic .K (6 )},
61
+ {symbolic .K (7 ), symbolic .K (8 ), symbolic .K (9 )},
62
+ }
63
+
64
+ // Test
65
+ me := symbolic .ConcretizeMatrixExpression (x )
66
+
67
+ // Check that me is a KMatrix
68
+ if _ , ok := me .(symbolic.KMatrix ); ! ok {
69
+ t .Errorf ("Expected a KMatrix; received %T" , me )
70
+ }
71
+
72
+ // Check that me is the correct KMatrix (i.e., it has the correct dimensions)
73
+ if me .Dims ()[0 ] != 3 || me .Dims ()[1 ] != 3 {
74
+ t .Errorf ("Expected a 3x3 KMatrix; received %dx%d KMatrix" , me .Dims ()[0 ], me .Dims ()[1 ])
75
+ }
76
+
77
+ }
78
+
79
+ /*
80
+ TestMatrixExpression_ConcretizeMatrixExpression2
81
+ Description:
82
+
83
+ Tests the conversion of a slice of slices of Monomials to a MonomialMatrix.
84
+ */
85
+ func TestMatrixExpression_ConcretizeMatrixExpression2 (t * testing.T ) {
86
+ // Setup
87
+ m := symbolic .NewVariable ().ToMonomial ()
88
+ x := [][]symbolic.ScalarExpression {
89
+ {m , m },
90
+ {m , m },
91
+ }
92
+
93
+ // Test
94
+ me := symbolic .ConcretizeMatrixExpression (x )
95
+
96
+ // Check that me is a MonomialMatrix
97
+ if _ , ok := me .(symbolic.MonomialMatrix ); ! ok {
98
+ t .Errorf ("Expected a MonomialMatrix; received %T" , me )
99
+ }
100
+
101
+ // Check that me is the correct MonomialMatrix (i.e., it has the correct dimensions)
102
+ if me .Dims ()[0 ] != 2 || me .Dims ()[1 ] != 2 {
103
+ t .Errorf ("Expected a 2x2 MonomialMatrix; received %dx%d MonomialMatrix" , me .Dims ()[0 ], me .Dims ()[1 ])
104
+ }
105
+ }
106
+
107
+ /*
108
+ TestMatrixExpression_ConcretizeMatrixExpression3
109
+ Description:
110
+
111
+ Tests the conversion of a slice of slices of Polynomials to a PolynomialMatrix.
112
+ */
113
+ func TestMatrixExpression_ConcretizeMatrixExpression3 (t * testing.T ) {
114
+ // Setup
115
+ p := symbolic .NewVariable ().ToPolynomial ()
116
+ x := [][]symbolic.ScalarExpression {
117
+ {p , p },
118
+ {p , p },
119
+ }
120
+
121
+ // Test
122
+ me := symbolic .ConcretizeMatrixExpression (x )
123
+
124
+ // Check that me is a PolynomialMatrix
125
+ if _ , ok := me .(symbolic.PolynomialMatrix ); ! ok {
126
+ t .Errorf ("Expected a PolynomialMatrix; received %T" , me )
127
+ }
128
+
129
+ // Check that me is the correct PolynomialMatrix (i.e., it has the correct dimensions)
130
+ if me .Dims ()[0 ] != 2 || me .Dims ()[1 ] != 2 {
131
+ t .Errorf ("Expected a 2x2 PolynomialMatrix; received %dx%d PolynomialMatrix" , me .Dims ()[0 ], me .Dims ()[1 ])
132
+ }
133
+ }
134
+
135
+ /*
136
+ TestMatrixExpression_ConcretizeMatrixExpression4
137
+ Description:
138
+
139
+ Tests the conversion of a slice of slices of Variable objects to a VariableMatrix.
140
+ */
141
+ func TestMatrixExpression_ConcretizeMatrixExpression4 (t * testing.T ) {
142
+ // Setup
143
+ v := symbolic .NewVariable ()
144
+ x := [][]symbolic.ScalarExpression {
145
+ {v , v },
146
+ {v , v },
147
+ {v , v },
148
+ }
149
+
150
+ // Test
151
+ me := symbolic .ConcretizeMatrixExpression (x )
152
+
153
+ // Check that me is a VariableMatrix
154
+ if _ , ok := me .(symbolic.VariableMatrix ); ! ok {
155
+ t .Errorf ("Expected a VariableMatrix; received %T" , me )
156
+ }
157
+
158
+ // Check that me is the correct VariableMatrix (i.e., it has the correct dimensions)
159
+ if me .Dims ()[0 ] != 3 || me .Dims ()[1 ] != 2 {
160
+ t .Errorf ("Expected a 3x2 VariableMatrix; received %dx%d VariableMatrix" , me .Dims ()[0 ], me .Dims ()[1 ])
161
+ }
162
+
163
+ }
164
+
165
+ /*
166
+ TestMatrixExpression_ConcretizeMatrixExpression5
167
+ Description:
168
+
169
+ Tests the conversion of a slice of slices constaining constants (K) and variables (symbolic.variable) expressions
170
+ to a MonomialMatrix.
171
+ */
172
+ func TestMatrixExpression_ConcretizeMatrixExpression5 (t * testing.T ) {
173
+ // Setup
174
+ k := symbolic .K (2 )
175
+ v := symbolic .NewVariable ()
176
+ x := [][]symbolic.ScalarExpression {
177
+ {k , v },
178
+ {v , k },
179
+ }
180
+
181
+ // Test
182
+ me := symbolic .ConcretizeMatrixExpression (x )
183
+
184
+ // Check that me is a MonomialMatrix
185
+ if _ , ok := me .(symbolic.MonomialMatrix ); ! ok {
186
+ t .Errorf ("Expected a MonomialMatrix; received %T" , me )
187
+ }
188
+
189
+ // Check that me is the correct MonomialMatrix (i.e., it has the correct dimensions)
190
+ if me .Dims ()[0 ] != 2 || me .Dims ()[1 ] != 2 {
191
+ t .Errorf ("Expected a 2x2 MonomialMatrix; received %dx%d MonomialMatrix" , me .Dims ()[0 ], me .Dims ()[1 ])
192
+ }
193
+ }
0 commit comments