@@ -73,3 +73,205 @@ func TestUtil_Identity2(t *testing.T) {
7373 }
7474
7575}
76+
77+ /*
78+ TestUtil_FindInSlice1
79+ Description:
80+
81+ Tests the find in slice function for strings!
82+ (string in slice)
83+ */
84+ func TestUtil_FindInSlice1 (t * testing.T ) {
85+ // Constant
86+ slice0 := []string {"Why" , "test" , "this" , "?" }
87+
88+ // Find!
89+ foundIndex , err := optim .FindInSlice ("?" , slice0 )
90+ if err != nil {
91+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
92+ }
93+
94+ if foundIndex != 3 {
95+ t .Errorf (
96+ "Expected index of string to be 3; received %v." , foundIndex ,
97+ )
98+ }
99+ }
100+
101+ /*
102+ TestUtil_FindInSlice2
103+ Description:
104+
105+ Tests the find in slice function for strings!
106+ (string NOT in slice)
107+ */
108+ func TestUtil_FindInSlice2 (t * testing.T ) {
109+ // Constant
110+ slice0 := []string {"Why" , "test" , "this" , "?" }
111+
112+ // Find!
113+ foundIndex , err := optim .FindInSlice ("llama" , slice0 )
114+ if err != nil {
115+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
116+ }
117+
118+ if foundIndex != - 1 {
119+ t .Errorf (
120+ "Expected index of string to be -1; received %v." , foundIndex ,
121+ )
122+ }
123+ }
124+
125+ /*
126+ TestUtil_FindInSlice3
127+ Description:
128+
129+ Tests the find in slice function for ints!
130+ (int in slice)
131+ */
132+ func TestUtil_FindInSlice3 (t * testing.T ) {
133+ // Constant
134+ slice0 := []int {1 , 3 , 7 , 11 }
135+
136+ // Find!
137+ foundIndex , err := optim .FindInSlice (1 , slice0 )
138+ if err != nil {
139+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
140+ }
141+
142+ if foundIndex != 0 {
143+ t .Errorf (
144+ "Expected index of string to be 0; received %v." , foundIndex ,
145+ )
146+ }
147+ }
148+
149+ /*
150+ TestUtil_FindInSlice4
151+ Description:
152+
153+ Tests the find in slice function for ints!
154+ (int NOT in slice)
155+ */
156+ func TestUtil_FindInSlice4 (t * testing.T ) {
157+ // Constant
158+ slice0 := []int {1 , 3 , 7 , 11 }
159+
160+ // Find!
161+ foundIndex , err := optim .FindInSlice (21 , slice0 )
162+ if err != nil {
163+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
164+ }
165+
166+ if foundIndex != - 1 {
167+ t .Errorf (
168+ "Expected index of string to be -1; received %v." , foundIndex ,
169+ )
170+ }
171+ }
172+
173+ /*
174+ TestUtil_FindInSlice5
175+ Description:
176+
177+ Tests the find in slice function for uint64!
178+ (uint64 in slice)
179+ */
180+ func TestUtil_FindInSlice5 (t * testing.T ) {
181+ // Constant
182+ slice0 := []uint64 {1 , 3 , 7 , 11 }
183+ var x uint64 = 1
184+
185+ // Find!
186+ foundIndex , err := optim .FindInSlice (x , slice0 )
187+ if err != nil {
188+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
189+ }
190+
191+ if foundIndex != 0 {
192+ t .Errorf (
193+ "Expected index of string to be 0; received %v." , foundIndex ,
194+ )
195+ }
196+ }
197+
198+ /*
199+ TestUtil_FindInSlice6
200+ Description:
201+
202+ Tests the find in slice function for uint64!
203+ (uint64 NOT in slice)
204+ */
205+ func TestUtil_FindInSlice6 (t * testing.T ) {
206+ // Constant
207+ slice0 := []uint64 {1 , 3 , 7 , 11 }
208+ var x uint64 = 21
209+
210+ // Find!
211+ foundIndex , err := optim .FindInSlice (x , slice0 )
212+ if err != nil {
213+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
214+ }
215+
216+ if foundIndex != - 1 {
217+ t .Errorf (
218+ "Expected index of string to be -1; received %v." , foundIndex ,
219+ )
220+ }
221+ }
222+
223+ /*
224+ TestUtil_FindInSlice7
225+ Description:
226+
227+ Tests the find in slice function for strings!
228+ (Variable in slice)
229+ */
230+ func TestUtil_FindInSlice7 (t * testing.T ) {
231+ // Constant
232+ m := optim .NewModel ("test-util-findinslice7" )
233+ vv1 := m .AddVariableVector (100 )
234+ slice0 := vv1 .Elements
235+
236+ // Find!
237+ indexUnderTest := 2
238+ foundIndex , err := optim .FindInSlice (vv1 .Elements [indexUnderTest ], slice0 )
239+ if err != nil {
240+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
241+ }
242+
243+ if foundIndex != indexUnderTest {
244+ t .Errorf (
245+ "Expected index of string to be %v; received %v." ,
246+ indexUnderTest , foundIndex ,
247+ )
248+ }
249+ }
250+
251+ /*
252+ TestUtil_FindInSlice4
253+ Description:
254+
255+ Tests the find in slice function for strings!
256+ (int NOT in slice)
257+ */
258+ func TestUtil_FindInSlice8 (t * testing.T ) {
259+ // Constant
260+ m := optim .NewModel ("test-util-findinslice7" )
261+ vv1 := m .AddVariableVector (100 )
262+ slice0 := vv1 .Elements
263+
264+ // Find!
265+ newVar := m .AddVariable ()
266+ foundIndex , err := optim .FindInSlice (newVar , slice0 )
267+ if err != nil {
268+ t .Errorf ("Received an error while trying to find valid string: %v" , err )
269+ }
270+
271+ if foundIndex != - 1 {
272+ t .Errorf (
273+ "Expected index of string to be %v; received %v." ,
274+ - 1 , foundIndex ,
275+ )
276+ }
277+ }
0 commit comments