2using System.Collections.Generic;
15 static readonly String PROPERTIES_FILE =
"test.properties";
16 static String workingDir;
20 static Logger logger = LogManager.GetCurrentClassLogger();
23 public static void OneTimeSetup()
25 logger.Debug(
"TestGAMSSymbolRecord | OneTimeSetup");
28 logger.Debug(
"TestGAMSSymbolRecord | oneTimeSetup");
39 public void TearDown()
46 public void TestDisposedSymbolRecord()
48 logger.Debug(
"Entering TestGAMSSymbolRecord | testDisposedSymbolRecord");
49 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testDisposedSymbolRecord";
64 Assert.Throws<NullReferenceException>(() => record.
MoveNext());
68 public void TestDisposedAllSymbolRecords()
70 logger.Debug(
"Entering TestGAMSSymbolRecord | testDisposedAllSymbolRecords");
71 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testDisposedAllSymbolRecords";
89 Console.WriteLine(record2.
Text);
90 Assert.Fail(
"do not expect an operation on GAMSSetRecord after disposed");
92 catch (NullReferenceException e)
94 Assert.True(record2 ==
null,
"expect GAMSSetRecord object to be null after disposed");
111 Assert.Fail(
"do not expect an operation on GAMSParameterRecord after disposed");
113 catch (NullReferenceException e)
115 Assert.True(record2 ==
null,
"expect GAMSParameterRecord object to be null after disposed");
132 Console.WriteLine(record.
Level);
133 Assert.Fail(
"do not expect an operation on GAMSVariableRecord after disposed");
135 catch (NullReferenceException e)
137 Assert.True(record ==
null,
"expect GAMSVariableRecord object to be null after disposed");
143 public void TestOrderOfDisposedSymbolRecords()
145 logger.Debug(
"Entering TestGAMSSymbolRecord | testOrderOfDisposedSymbolRecords");
146 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testOrderOfDisposedSymbolRecords";
158 String[] keys1 = rec1.
Keys;
159 double value1 = rec1.
Value;
170 Assert.Fail(
"do not expect an operation on GAMParameterRecord after disposed");
172 catch (NullReferenceException e)
174 Assert.True((rec1 ==
null && rec2 ==
null),
"expect GAMSParameterRecord object to be null after disposed");
182 Assert.True(value1 == rec1.
Value,
"expect equuals equauls??");
183 Assert.True(rec1.
Key(0).Equals(keys1[0]),
"expect equuals equauls??");
184 Assert.True(rec1.
Key(1).Equals(keys1[1]),
"expect equuals equauls??");
190 Assert.Fail(
"do not expect an operation on GAMParameterRecord after disposed");
192 catch (NullReferenceException e)
194 Assert.True((rec1 !=
null && rec2 ==
null),
"expect GAMSParameterRecord object to be null after disposed");
199 public void TestEquivalentSymbolRecord()
201 logger.Debug(
"Entering TestGAMSSymbolRecord | testEquivalentSymbolRecord");
202 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testEquivalentSymbolRecord";
216 Assert.True(rec1.
Equals(rec2),
"expect rec1 and rec2 to be equivalent");
217 Assert.True(rec1.
Equals(rec3),
"expect rec1 and rec3 to be equivalent");
218 Assert.False(rec1 == rec2,
"rec1 and rec2 are not the same C# object");
219 Assert.False(rec1 == rec3,
"rec1 and rec3 are not the same C# object");
222 Assert.False(rec1.
Equals(rec4),
"rec1 and rec4 are not equivalent");
223 Assert.False(rec1 == rec4,
"rec1 and rec4 are not the same C# object");
226 Assert.True(rec5.
Equals(rec4),
"expect rec5 and rec4 to be equivalent");
227 Assert.False(rec5 == rec4,
"rec5 and rec4 are not the same C# object");
230 Assert.True(rec6.
Equals(rec1),
"expect rec6 and rec1 to be equivalent");
231 Assert.False(rec6 == rec1,
"rec6 and rec1 are not the same C# object");
237 Assert.False(rec1.
Equals(rec2),
"expect rec1 and rec2 to be equivalent");
238 Assert.False(rec1 == rec2,
"rec1 and rec2 are not the same C# object");
246 if (rec.
Key(0).Equals(
"topeka"))
248 Assert.True(rec.
Equals(lastRec),
"expect LastRec and rec to be equivalent");
249 Assert.False(rec == lastRec,
"rec and lastRec are not the same C# object");
253 String[] slice =
new String[] {
" ",
"chicago" };
258 Assert.True(lastSlicedRecord.
Equals(record),
"expect LastRec and rec to be equivalent");
259 Assert.False(lastSlicedRecord == record,
"lastSlicedRecord and record are not the same C# object");
265 Assert.True(lastRec.
Equals(firstRec),
"cost has only 1 record, expect LastRec and firstRec to be equivalent");
266 Assert.False(lastRec == firstRec,
"lastRec and firstRec are not the same C# object");
271 String[] slice =
new String[] {
" ",
"topeka" };
274 Assert.True(firstSlicedRec.
Equals(firstRec),
"expect firstSlicedRec and firstRec to be equivalent");
275 Assert.False(firstSlicedRec == firstRec,
"firstSlicedRec and firstRec are not the same C# object");
283 Assert.True(r1.
Equals(r2),
"expect r1 and r2 to be equivalent");
284 Assert.False(r1 == r2,
"expect r1 and r2 with different memory references");
285 Assert.True(r1.
Equals(r3),
"expect r1 and r3 to be equivalent");
286 Assert.True(r1 == r3,
"expect r1 and r3 with the same memory reference");
288 Assert.True(r1.
Equals(r4),
"expect r1 and r4 to be equivalent");
289 Assert.False(r1 == r4,
"expect r1 and r4 with different memory references");
291 logger.Debug(
"Exiting TestGAMSSymbolRecord | testEquivalentSymbolRecord");
295 public void TestEquivalentSymbolRecord_IteratingRecord()
297 logger.Debug(
"Entering TestGAMSSymbolRecord | testEquivalentSymbolRecord_IteratingRecord");
300 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testEquivalentSymbol";
315 Assert.True(record.
Equals(ny),
"expect ny as first record and to be equivalent to record");
320 if (record.
Key(0).Equals(
"new-york"))
322 Assert.True(record.
Equals(ny),
"expect record and ny to be equivalent");
324 else if (record.
Key(0).Equals(
"chicago"))
326 Assert.True(record.
Equals(chicago),
"expect record and chicago to be equivalent");
328 else if (record.
Key(0).Equals(
"topeka"))
330 Assert.True(record.
Equals(topeka),
"expect record and topeka to be equivalent");
334 Assert.Fail(
"do not expect a record of b with other key than [(new-york),(chicago),(topeka)]");
336 Assert.AreEqual(1, record.
Keys.Length,
"expect record with 1 dimensions");
339 Assert.AreEqual(3, count,
"expect 3 iterating record from j.");
346 if ((record.
Key(0).Equals(
"seattle") && record.
Key(1).Equals(
"chicago")))
348 Assert.True(record.
Equals(seattle_chicago),
"expect record and seattle_chicago to be equivalent");
352 Assert.False(record.
Equals(seattle_chicago),
"record and seattle_chicago are not equivalent");
361 if ((record.
Key(0).Equals(
"seattle") && record.
Key(1).Equals(
"topeka")))
363 Assert.True(record.
Equals(seattle_topeka),
"expect record and seattle_chicago to be equivalent");
367 Assert.False(record.
Equals(seattle_topeka),
"record and seattle_chicago are not equivalent");
378 if (record.
Key(0).Equals(
"san-diego"))
380 Assert.True(record.
Equals(sandiego),
"expect record and ny to be equivalent");
382 else if (record.
Key(0).Equals(
"seattle"))
384 Assert.True(record.
Equals(seattle),
"expect record and chicago to be equivalent");
388 Assert.Fail(
"do not expect a record of b with other key than [(san-diego),(seattle)]");
393 logger.Debug(
"Exiting TestGAMSSymbolRecord | testEquivalentSymbolRecord_IteratingRecord");
397 public void TestGetKeys()
399 logger.Debug(
"Entering TestGAMSSymbolRecord | testGetKeys");
401 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testGetKeys";
411 Assert.AreEqual(rec_i.
Keys.Length, 1,
"expect i with 1 dimension");
412 Assert.True(rec_i.
Keys[0].Equals(
"san-diego"),
"expect (sandiego) as keys of last record of i");
415 Assert.AreEqual(rec_d.
Keys.Length, 2,
"expect d with 2 dimension");
416 Assert.True(rec_d.
Keys[0].Equals(
"san-diego"),
"expect (sandiego, topeka) as keys of last record of d");
417 Assert.True(rec_d.
Keys[1].Equals(
"topeka"),
"expect (sandiego, topeka) as keys of last record of d");
420 Assert.AreEqual(rec_f.
Keys.Length, 0,
"expect scalar f with 0 dimension");
423 Assert.AreEqual(rec_x.
Keys.Length, 2,
"expect x with 2 dimension");
424 Assert.True(rec_x.
Keys[0].Equals(
"san-diego"),
"expect (sandiego, topeka) as keys of last record of x");
425 Assert.True(rec_x.
Keys[1].Equals(
"topeka"),
"expect (sandiego, topeka) as keys of last record of x");
428 Assert.AreEqual(rec_cost.
Keys.Length, 0,
"expect cost with 0 dimension");
431 Assert.AreEqual(rec_demand.
Keys.Length, 1,
"expect demand with 1 dimension");
432 Assert.True(rec_demand.
Keys[0].Equals(
"topeka"),
"expect (topeka) as keys of last record of d");
434 logger.Debug(
"Exiting TestGAMSSymbolRecord | testGetKeys");
438 public void TestGetKey_index()
440 logger.Debug(
"Entering TestGAMSSymbolRecord | testGetKey_index");
441 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testGetKeysIndex";
451 Assert.True(rec_i.
Key(0).Equals(
"seattle"),
"expect (seattle) as keys of last record of i");
455 Assert.True(rec_d.
Key(0).Equals(
"san-diego"),
"expect (sandiego, topeka) as keys of last record of d");
456 Assert.True(rec_d.
Key(1).Equals(
"topeka"),
"expect (sandiego, topeka) as keys of last record of d");
460 Assert.True(rec_x.
Key(0).Equals(
"san-diego"),
"expect (sandiego, topeka) as keys of last record of x");
461 Assert.True(rec_x.
Key(1).Equals(
"topeka"),
"expect (sandiego, topeka) as keys of last record of x");
465 Assert.True(rec_demand.
Key(0).Equals(
"new-york"),
"expect (new-york) as keys of last record of demand");
467 logger.Debug(
"Exiting TestGAMSSymbolRecord | testGetKey_index");
GAMSVariable GetVariable(string variableIdentifier)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSSet GetSet(string setIdentifier)
GAMSEquation GetEquation(string equationIdentifier)
new GAMSEquationRecord FindRecord(params string[] keys)
new GAMSEquationRecord FirstRecord()
new GAMSEquationRecord LastRecord()
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
new GAMSParameterRecord LastRecord()
new GAMSParameterRecord FindRecord(params string[] keys)
new GAMSParameterRecord FirstRecord()
new GAMSSetRecord LastRecord()
new GAMSSetRecord FirstRecord()
new GAMSSetRecord FindRecord(params string[] keys)
override bool Equals(object obj)
GAMSSymbolRecord FirstRecord()
GAMSSymbolRecord FindRecord(params string[] keys)
GAMSSymbolRecord LastRecord()
new GAMSVariableRecord FindRecord(params string[] keys)
new GAMSVariableRecord FirstRecord()
new GAMSVariableRecord LastRecord()
GAMSJob AddJobFromGamsLib(string model, GAMSCheckpoint checkpoint=null, string jobName=null)
static void prepare(String dir)
Prepare directory by checking its existence. If exists, (non - recursively) delete all its contents,...
static void initializeTestFrom(String filename, String subdir)
initialize class properties from fileName and prepare directory subdir