2using System.Collections.Generic;
13 static readonly String PROPERTIES_FILE =
"test.properties";
18 static Logger logger = LogManager.GetCurrentClassLogger();
21 public static void OneTimeSetUp()
23 logger.Debug(
"entering TestGAMSDatabase | OneTimeSetUp");
26 wsInfo.WorkingDirectory =
HouseKeeper.gamsWorkingDir;
31 initializeDatabase(globalDB);
32 logger.Debug(
"exiting TestGAMSDatabase | OneTimeSetUp");
36 public static void OneTimeTearDown()
38 logger.Debug(
"entering TestGAMSDatabase | OneTimeTearDown");
42 logger.Debug(
"exiting TestGAMSDatabase | OneTimeTearDown");
53 public void TearDown()
60 public void testAddSet()
62 logger.Debug(
"entering TestGAMSDatabase | testAddSet");
66 String relaxedDomainName =
"*";
69 String s11Name =
"set11";
72 Assert.AreEqual(db, s11.
GAMSDatabase,
"expect same db reference");
73 Assert.That(s11.
Dim == 1,
"expect s11 with one dimension");
74 Assert.NotNull(s11.
Domains,
"do not expect a NULL list object returned");
75 Assert.That(s11.
Domains.Count > 0,
"do not expect an empty list returned");
76 foreach (Object dom
in s11.Domains)
78 Assert.That(dom is String,
"expect String as relaxed domain");
79 Assert.That(relaxedDomainName.Equals(dom),
"expect [" + relaxedDomainName +
80 "] string as a relaxed domain.");
82 Assert.That(s11Name.Equals(s11.Name),
"expect [" + s11Name +
"] as set name.");
83 Assert.That(s11.Text.Equals(
""),
"expect an expmty string as set explanatory text.");
84 testSymbolWithoutARecord(s11, s11Name);
85 Assert.AreEqual(1, db.
NrSymbols,
"expect one symbol in database [db]");
88 String s12Name =
"set12";
89 String s12Text =
"This is explanatory text for set12";
92 Assert.AreEqual(db, s12.
GAMSDatabase,
"expect same db reference");
93 Assert.That(s12.
Dim == 1,
"expect s12 with one dimension");
94 Assert.NotNull(s12.
Domains,
"do not expect a NULL list object returned.");
95 Assert.That(s12.
Domains.Count > 0,
"do not expect an empty list returned");
96 foreach (Object dom
in s12.Domains)
98 Assert.That(dom is String,
"expect string as relaxed domain.");
99 Assert.That(relaxedDomainName.Equals(dom),
"expect ["+
100 relaxedDomainName+
"] string as relaxed domain.");
102 Assert.That(s12Name.Equals(s12.Name),
"expect [" + s12Name +
"] as set name.");
103 Assert.That(s12.Text.Equals(s12Text),
"expect [" + s12Text +
"] as set explanatory text");
104 testSymbolWithoutARecord(s12, s12Name);
105 Assert.AreEqual(2, db.
NrSymbols,
"expect two symbols in db");
107 List<String> plants =
new List<String> {
"Seattle",
"San-Diego" };
108 foreach (String p
in plants)
114 Assert.AreEqual(1, rec.
Keys.Count());
115 Assert.AreEqual(
"Seattle", rec.
Keys[0]);
117 rec =
set.LastRecord();
118 Assert.AreEqual(1, rec.
Keys.Count());
119 Assert.AreEqual(
"San-Diego", rec.
Keys[0]);
121 Assert.AreEqual(2, db.
NrSymbols,
"expect 2 symbols in database [db]");
124 String s2Name =
"set2";
125 String s2Text =
"This is explanatory text for set2";
130 Assert.That(s2.
Dim == 2);
132 Assert.That(s2.
Domains.Count > 0);
134 foreach (Object dom
in s2.Domains)
136 Assert.That(s2Name.Equals(s2.Name));
137 Assert.That(relaxedDomainName.Equals((String)dom));
139 Assert.That(s2Name.Equals(s2.Name));
140 Assert.That(s2Text.Equals(s2.Text));
141 testSymbolWithoutARecord(s2, s2Name);
145 String s3Name =
"set3";
146 String s3Text =
"This is explanatory text for set3";
147 Object[] domains1 =
new Object[] { s11 };
151 Assert.That(s3.
Dim == 1);
153 Assert.That(s3.
Domains.Count > 0);
155 foreach (Object dom
in s3.Domains)
163 Assert.That(s11.Name.Equals(
set.Name));
165 Assert.That(s3Name.Equals(s3.Name));
166 Assert.That(s3Text.Equals(s3.Text));
167 testSymbolWithoutARecord(s3, s3Name);
171 String s4Name =
"set4";
172 String s4Text =
"This is explanatory text for set4";
173 Object[] domains2 =
new Object[] { s11, s12 };
177 Assert.That(s4.
Dim == 2);
179 Assert.That(s4.
Domains.Count > 0);
184 Assert.That(s11.Name.Equals(domSet1.
Name));
188 Assert.That(s12 != domSet2);
189 Assert.That(s4.
Text.Equals(s4Text));
191 Assert.That(s4Name.Equals(s4.
Name));
192 Assert.That(s4Text.Equals(s4.
Text));
194 testSymbolWithoutARecord(s4, s4Name);
199 FileInfo dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir +
200 Path.DirectorySeparatorChar + db.
Name +
202 Assert.False(dbFile.Exists);
208 Assert.That(dbFile.Exists);
209 Assert.That(dbFile.Length > 0);
213 String gdxName =
"testAddSetABC";
214 dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir +
215 Path.DirectorySeparatorChar + gdxName +
217 Assert.False(dbFile.Exists);
222 Assert.That(dbFile.Exists);
223 Assert.That(dbFile.Length > 0);
225 logger.Debug(
"exiting TestGAMSDatabase | testAddSet");
229 public void testAddSetZeroDimension()
231 logger.Debug(
"test exception set withzero dimension");
236 public void testAddSetWithDuplicateIdentifier()
238 logger.Debug(
"test exception set with duplicate identifier");
244 public void testAddSetWithNullIdentifier()
246 logger.Debug(
"test exception set with null identifier");
251 public void testAddParameterWithNullIdentifier()
253 logger.Debug(
"test exception parameter with null identifier");
258 public void testAddVariableWithNullIdentifier()
260 logger.Debug(
"test exception variable with null identifier");
265 public void testAddEquationWithNullIdentifier()
267 logger.Debug(
"test exception equation with null identifier");
272 public void testAddSetWithEmptyIdentifier()
274 logger.Debug(
"test exception set with empty identifier");
279 public void testAddParamterWithEmptyIdentifier()
281 logger.Debug(
"test exception paramter with empty identifier");
286 public void testAddVariableWithEmptyIdentifier()
288 logger.Debug(
"test exception variable with empty identifier");
293 public void testAddEquationWithEmptyIdentifier()
295 logger.Debug(
"test exception equation with empty identifier");
300 public void testAddParameter()
302 logger.Debug(
"entering TestGAMSDatabase | testAddParamter");
306 String pName =
"parameter0";
309 Assert.That(p0.
Dim == 0);
310 Assert.That(pName.Equals(p0.
Name));
312 testSymbolWithoutARecord(p0, pName);
313 logger.Debug(
"extiting TestGAMSDatabase | testAddParamter");
317 public void testAddParamterWithDuplicateName()
319 logger.Debug(
"test exception parameter with duplicate name");
325 public void testAddEquation()
327 logger.Debug(
"TestGAMSDatabase | testAddEquation");
333 String eqText =
"Equality";
335 logger.Info(
"equation z added");
337 Assert.AreEqual(1, eq1.
Dim,
"expect eq1 with 1 dimension.");
339 Assert.That(eq1.
Domains.Count > 0);
340 Assert.That(eqText.Equals(eq1.
Text));
341 Assert.That(eqName.Equals(eq1.
Name));
343 testSymbolWithoutARecord(eq1, eqName);
347 logger.Info(
"equation z retrieved");
348 Assert.AreEqual(eq1.
Dim, 1);
349 Assert.AreEqual(z.
Dim, 1);
350 Assert.AreEqual(db, z.
GAMSDatabase,
"expect same database reference.");
353 Assert.AreEqual(eqText, z.
Text);
355 logger.Debug(
"TestGAMSDatabase | testAddEquation");
359 public void testAddVariable()
361 logger.Debug(
"TestGAMSDatabase | testAddVariable");
372 Assert.AreEqual(1, x.
Dim);
374 Assert.AreEqual(
"binary variable x", x.
Text);
378 Assert.AreEqual(1, y.
Dim);
380 Assert.AreEqual(
"integer variable y", y.
Text);
385 logger.Debug(
"TestGAMSDatabase | testAddVariable");
389 public void testGetNonExistingSet1()
391 logger.Info(
"test exception non exisiting Set1");
396 public void testGetNonExistingSet2()
398 logger.Info(
"test exception non exisiting Set2");
403 public void testGetNonExistingParameter()
405 logger.Info(
"test exception non exisiting parameter");
410 public void testGetNonExistingVariable()
412 logger.Info(
"test exception non exisiting variable");
417 public void testGetNonEistingEquation()
419 logger.Info(
"test exception non exisiting equation");
424 public void testGetSymbolNullIdentifier()
426 logger.Info(
"test exception symbol null identifier");
431 public void testGetSetNullIdentifier()
433 logger.Info(
"test exception set null identifier");
438 public void testGetParameterNullIdentifier()
440 logger.Info(
"test exception parameter null identifier");
445 public void testGetVariableNullIdentifier()
447 logger.Info(
"test exception variable null identifier");
452 public void testGetEquationNullIdentifier()
454 logger.Info(
"test exception equation null identifier");
459 public void testGetSymbolEmptyIdentifier()
461 logger.Info(
"test exception symbol empty identifier");
466 public void testGetSetEmptyIdentifier()
468 logger.Info(
"test exception set empty identifier");
473 public void testGetParamterEmptyIdentifier()
475 logger.Info(
"test exception paramter empty identifier");
480 public void testGetEquationEmptyidentifier()
482 logger.Info(
"test exception equation empty identifier");
487 public void testGetVariableEmptyIdentifier()
489 logger.Info(
"test exception variable empty identifier");
494 public void testAccessToClearedDatabase()
496 logger.Debug(
"entering TestGAMSDatabase | testAccessToClearedDatabse");
503 logger.Info(
"database db cleared");
504 Assert.AreEqual(numberOfSymbol, db.
NrSymbols);
508 logger.Info(
"symbol [" + symbol.ToString() +
"] retrieved from database db");
509 Assert.NotNull(symbol);
512 logger.Debug(
"exiting TestGAMSDatabase | testAccessToClearedDatabase");
516 public void testAccessToDisposedDatabase1()
518 logger.Info(
"test exception access to disposed database 1");
522 Assert.NotNull(db.
GetSet(
"plants"));
524 Assert.NotNull(symbol);
527 logger.Info(
"database db disposed");
537 public void testAccessToDisposedDatabase2()
539 logger.Debug(
"test exception access to disposed databse 2");
542 Assert.NotNull(db.
GetSet(
"plants"));
544 logger.Debug(
"database db disposed");
549 public void testExport1()
551 logger.Debug(
"entering TestGAMSDatabase | testExport1");
552 String gdxFileName = globalDB.
Name;
553 FileInfo dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir +
554 Path.DirectorySeparatorChar +
557 Assert.False(dbFile.Exists,
"do not expect an existence of [" + dbFile.FullName +
"].");
559 logger.Info(
"database globalDB exported");
562 Assert.That(dbFile.Exists,
"expect an existence of [" + dbFile.Name +
"]");
563 Assert.That(dbFile.Length > 0,
"expect non-empty [" + dbFile.FullName +
"].");
564 logger.Debug(
"exiting testGAMSDAtabase | testExport1");
568 public void testExport2()
570 logger.Debug(
"entering TestGAMSDatabase | testExport2");
572 db = ws.
AddDatabase(globalDB,
"testExport2_" + DateTime.Now.ToString(
"yyyyMMdd_HHmmss"));
573 String gdxFileName = db.
Name;
574 FileInfo dbFile =
new FileInfo(ws.
WorkingDirectory + Path.DirectorySeparatorChar +
576 Assert.False(dbFile.Exists,
"do not expect an existence of ["+dbFile.FullName+
"].");
580 logger.Info(
"database db exported");
582 Assert.That(dbFile.Exists,
"expect an existence of ["+dbFile.FullName+
"].");
583 Assert.That(dbFile.Length > 0,
"expect non-empty ["+dbFile.FullName+
"].");
584 logger.Debug(
"exiting TestGAMSDatabase | testExport2");
588 public void testExportDomainInfo()
590 logger.Debug(
"entering TestGAMSDatabase | testExportDomainInfo");
593 String dbName =
"testExportDomainInfo_" + DateTime.Now.ToString(
"yyyyMMdd_HHmmss");
596 Object[] domains =
new Object[] { db.
GetSet(
"plants"),
"*" };
597 db.
AddSet(
"testDomain1",
"this is a test parameter", domains);
599 domains =
new Object[] { db.
GetSet(
"plants"),
"markets" };
600 db.
AddParameter(
"testDomain2",
"this is a test parameter", domains);
603 logger.Info(
"database db exported");
605 String gdxFileName = db.
Name;
606 FileInfo dbFile =
new FileInfo(ws.
WorkingDirectory + Path.DirectorySeparatorChar +
609 logger.Debug(
"database from DGX file [" + dbFile.FullName +
"] added to gdxDb");
613 logger.Info(
"set [testDomain1] retrieved from databse gdxDb");
615 Assert.NotNull(t1,
"expect parameter [testDomain1] from gdxDB");
616 Assert.AreEqual(2, t1.
Domains.Count,
"expect parameter [testDomain1] with 2 domains");
617 Assert.That(t1.
Domains[0] is
GAMSSet,
"expect parameter [testDomain1] with regular domain");
618 Assert.AreEqual(
"plants", ((
GAMSSet)t1.
Domains[0]).Name,
"expect parameter [testDomain1] with regular domain [plants]");
619 Assert.That(t1.
Domains[1] is String,
"expect parameter [testDomain1] with relax domain");
620 Assert.AreEqual(
"*", (String)t1.
Domains[1],
"expect parameter [testDomain1] with relaxed domain (*)");
624 logger.Info(
"parameter [testDomain2] retrieved from database gdxDB");
626 Assert.NotNull(t2,
"expect parameter [testDomain1] from gdxDB");
627 Assert.AreEqual(2, t2.
Domains.Count,
"expect parameter [testDomain1] with 2 domains");
628 Assert.That(t2.
Domains[0] is
GAMSSet,
"expect parameter [testDomain1] with regular domain");
629 Assert.AreEqual(
"plants", ((
GAMSSet)t2.
Domains[0]).Name,
"expect parameter [testDomain1] with regular domain (plants)");
630 Assert.That(t2.
Domains[1] is
GAMSSet,
"expect parameter [testDomain1] with regular domain");
631 Assert.AreEqual(
"markets", ((
GAMSSet)t2.
Domains[1]).Name,
"expect parameter [testDomain1] with regular domain (markets)");
635 logger.Info(
"set [plants] retrieved from database gdxDb");
637 Assert.NotNull(i,
"expect parameter [plants] from gdxDB");
638 Assert.AreEqual(1, i.
Domains.Count,
"expect parameter [plants] with 1 domain");
639 Assert.That(i.
Domains[0] is String,
"expect parameter [plants] with relax domain");
640 Assert.AreEqual(
"*", (String)i.
Domains[0],
"expect parameter [plants] with relax domain (*)");
644 logger.Info(
"parameter [capacity] retrieved from database gdxDB");
646 Assert.NotNull(c,
"expect parameter [capacity] from gdxDB");
647 Assert.AreEqual(1, c.
Domains.Count,
"expect parameter [capacity] with 1 domain");
649 Assert.AreEqual(
"plants", ((
GAMSSet)c.
Domains[0]).Name,
"expect parameter [capacity] with regular domain (plants)");
653 logger.Info(
"parameter [demand] retrieved from database gdxDB");
655 Assert.NotNull(d,
"expect parameter [demand] from gdxDB");
656 Assert.AreEqual(1, d.
Domains.Count,
"expect parameter [demand] with one domain");
657 Assert.That(d.
Domains[0] is
GAMSSet,
"expect parameter [demand] with regular domain");
658 Assert.AreEqual(
"markets", ((
GAMSSet)d.
Domains[0]).Name,
"expect parameter [demand] with regular domain (markets)");
662 logger.Info(
"parameter [distance] retrieved from database gdxDB");
664 Assert.NotNull(distance,
"expect parameter [distance] from gdxDB");
665 Assert.AreEqual(2, distance.
Domains.Count,
"expect parameter [distance] with 2 domains");
666 foreach (Object dom
in d.Domains)
667 Assert.That(dom is
GAMSSet,
"expect parameter [distance] with true domain");
668 Assert.AreEqual(
"plants", ((
GAMSSet)distance.Domains[0]).Name,
"expect parameter [distance] with regular domain (plants)");
669 Assert.AreEqual(
"markets", ((
GAMSSet)distance.Domains[1]).Name,
"expect parameter [distance] with regular domain (markets)");
670 logger.Debug(
"exiting TestGAMSDatabase | testExportDomainInfo");
674 public void testExportWithGDXFileName()
676 logger.Debug(
"entering TestGAMSDatabase | testExportWithGDXFileName");
677 String gdxFileName =
"testExportWithGDXFileName_" + DateTime.Now.ToString(
"yyyyMMdd_HHmmss");
678 FileInfo dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir + Path.DirectorySeparatorChar +
680 Assert.False(dbFile.Exists,
"do not expect an existence of [" + dbFile.FullName +
"].");
682 globalDB.
Export(gdxFileName);
684 logger.Info(
"database globalDB exported to file " + gdxFileName);
686 Assert.That(dbFile.Exists,
"expect an existence of [" + dbFile.FullName +
"].");
687 Assert.That(dbFile.Length > 0,
"expect non-empty ["+dbFile.FullName+
"].");
688 logger.Debug(
"exiting TestGAMSDatabase | testExportWithGDXFileName");
692 public void testExportDisposedDatabase()
694 logger.Debug(
"test exception export disposed database");
698 logger.Info(
"database db disposed");
704 public void testDisposeExportedDatabase()
706 logger.Debug(
"TestGAMSDatabase | testDisposeExportedDatabase");
709 db = ws.
AddDatabase(globalDB,
"testDisposeExportedDatabase_"+DateTime.Now.ToString(
"yyyyMMdd_HHmmss"));
711 String gdxFileName = db.
Name;
712 FileInfo dbFile =
new FileInfo(ws.
WorkingDirectory + Path.DirectorySeparatorChar +
714 Assert.False(dbFile.Exists,
"do not expect an existence of [" + dbFile.FullName +
"].");
716 logger.Info(
"db exported");
720 logger.Info(
"db disposed");
723 Assert.That(dbFile.Exists,
"expect an existence of [" + dbFile.FullName +
"].");
724 Assert.That(dbFile.Length > 0,
"expect non-empty [" + dbFile.FullName +
"].");
725 logger.Debug(
"exiting TestGAMSDatabase | testDisposeExportedDatabase");
729 public void testExportDomainViolatedDatabase()
731 logger.Debug(
"test exception export domain violated database");
741 public void testExportSuppressedDomainCheckingDatabase()
743 logger.Debug(
"entering TestGAMSDatabase | testExportSuppressedDomainCheckingDatabase");
746 db = ws.
AddDatabase(globalDB,
"testExportSuppressedDomainCheckingDatabase_" + DateTime.Now.ToString(
"yyyyMMdd_HHmmss"));
750 String gdxFileName = db.
Name;
751 FileInfo dbFile =
new FileInfo(ws.
WorkingDirectory + Path.DirectorySeparatorChar +
753 Assert.False(dbFile.Exists,
"do not expect an existence of [" + dbFile.FullName +
"].");
755 db.SuppressAutoDomainChecking =
true;
759 logger.Debug(
"db disposed");
763 Assert.That(dbFile.Exists,
"expect an existence of [" + dbFile.FullName +
"].");
764 Assert.That(dbFile.Length > 0,
"expect non-empty [" + dbFile.FullName +
"].");
765 logger.Debug(
"exiting TestGAMSDatabase | testExportSuppressedDomainCheckingDatabase");
769 public void testExportNonSuppressedDomainCheckingDatabaseWithDomainViolation()
771 logger.Debug(
"test exception export non suppressed domain checking db with domain violation");
777 db.SuppressAutoDomainChecking =
false;
784 public void testCheckDomain1()
786 logger.Debug(
"entering TestGAMSDatabase | testCheckDomain1");
787 Assert.That(globalDB.
GetParameter(
"capacity").
CheckDomains(),
"expect Parameter [capacity] without domain violation");
789 Assert.That(globalDB.
GetParameter(
"distance").
CheckDomains(),
"expect Parameter [distance] without domain violation");
790 Assert.That(globalDB.
CheckDomains(),
"do not expect Database [globalDB] with domain violation");
791 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomain1");
795 public void testCheckDomain2()
797 logger.Debug(
"entering TestGAMSDatabase | testCheckDomain2");
805 Assert.That(db.
CheckDomains,
"do not expect Database [db] with domain violation");
806 Assert.That(i.
CheckDomains(),
"do not expect Set [plants] with domain violation");
807 Assert.That(c.
CheckDomains(),
"do not expect Parameter [capacity] with domain violation");
808 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomain2");
812 public void testCheckDomain3()
814 logger.Debug(
"entering TestGAMSDatabase | testCheckDomain3");
820 String cityName =
"Alburqueque";
822 Assert.False(db.
CheckDomains(),
"do not expect Database [db] with domain violation");
823 Assert.False(c.
CheckDomains(),
"expect Parameter [capacity] with domain violation");
833 Assert.AreEqual(info.
ViolRec.
Keys[0], cityName,
"expect 1 domain violation record of parameter [capacity] with key [" + cityName +
"].");
834 Assert.True(info.
ViolInd[0],
"expect 1 domain violation record of parameter [capaity] with violation array [true].");
838 Assert.AreEqual(1, dvCnt,
"do not expect more than 1 domain violation record of parameter [capacity].");
842 Assert.AreEqual(1, dvCnt,
"expect 1 domain violation record of parameter [capacity].");
843 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomain3");
847 public void testCheckDomain4()
849 logger.Debug(
"entering TestGAMSDatabase | testCheckDomain4");
857 d.
AddRecord(
new String[] {
"Seattle",
"aa" }).Value = 1;
858 d.
AddRecord(
new String[] {
"bb",
"Seattle" }).Value = 1;
859 d.
AddRecord(
new String[] {
"x",
"y" }).Value = 1;
861 Assert.False(d.
CheckDomains(),
"expect Parameter [distance] with domain violation");
866 foreach (String item2
in item.ViolRec.Keys)
868 Assert.NotNull(item2,
"do not expect a NULL key from domain violation record");
871 Assert.AreEqual(3, dvCnt,
"expect 3 domain violation records of parameter [distance].");
881 Assert.AreEqual(4, dvCnt,
"expect 4 domain violation records of database [db].");
882 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomain4");
886 public void testCheckDomainWithMaxViolation()
888 logger.Debug(
" TestGAMSDatabase | testCheckDomainWithMaxViolation");
898 d.
AddRecord(
new String[] {
"Seattle",
"aa" }).Value = 1;
899 d.
AddRecord(
new String[] {
"bb",
"Seattle" }).Value = 1;
900 d.
AddRecord(
new String[] {
"x",
"y" }).Value = 1;
910 Assert.AreEqual(3, dvCnt,
"expect 3 domain violation records of database [db].");
911 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomainWithMaxViolation");
915 public void testCheckDomainWithMaxViolationPerSymbol()
917 logger.Debug(
"entering TestGAMSDatabase | testCheckDomainWithMaxViolationPerSymbol");
927 d.
AddRecord(
new String[] {
"Seattle",
"aa" }).Value = 1;
928 d.
AddRecord(
new String[] {
"bb",
"Seattle" }).Value = 1;
929 d.
AddRecord(
new String[] {
"x",
"y" }).Value = 1;
934 Assert.AreEqual(3, dvCnt,
"expect 3 domain violation records of symbol [distance].");
939 Assert.AreEqual(2, dvCnt,
"expect 2 domain violation records of symbol [distance].");
949 Assert.AreEqual(3, dvCnt,
"expect 3 domain violation records of database [db].");
950 logger.Debug(
"exiting TestGAMSDatabase | testCheckDomainWithMaxViolationPerSymbol");
953 [Test, Timeout(20000)]
954 [Ignore(
"heavy load")]
955 public void testAddOneMillionSets()
957 logger.Debug(
"entering TestGAMSDatabase | testAddOneMillionSets");
962 Assert.NotNull(db,
"expect a successful creation of GAMSDatabase.");
964 for (
int i = 0; i < 1000000; i++)
966 Assert.AreEqual(1000000, db.
NrSymbols,
"expect 1,000,000 symbols in database.");
967 FileInfo dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir + Path.DirectorySeparatorChar +
969 Assert.False(dbFile.Exists,
"do not expect an existence of [" + dbFile.FullName +
"].");
974 Assert.That(dbFile.Exists,
"expect an existence of [" + db.
Name + dbFile.FullName +
"].");
975 Assert.That(dbFile.Length > 0,
"expect non-empty [" + dbFile.FullName +
"].");
976 Assert.AreEqual(1000000, db.
NrSymbols,
"expect 1,000,000 symbols in database.");
977 logger.Debug(
"exiting TestGAMSDatabase | testAddOneMillionSets");
980 [Test, Timeout(20000)]
981 [Ignore(
"heavy load")]
982 public void testAddOneMillionParameters()
984 logger.Debug(
"entering TestGAMSDatabase | testAddOneMillionParamters");
987 db = ws.
AddDatabase(
"testAddOneMillionParameters");
988 Assert.NotNull(db,
"expect a successful creation of GAMSDatabase.");
990 for (
int i = 0; i < 1000000; i++)
993 Assert.AreEqual(1000000, db.
NrSymbols,
"expect 1,000,000 symbols in database.");
996 Assert.NotNull(symbol,
"do not expect a NULL symbol instance.");
997 Assert.True(symbol is
GAMSParameter,
"expect a GAMSParameter instance");
998 Assert.AreEqual(
"parameter" + count, symbol.
Name,
"expect a parameter with name [parameter" + count +
"].");
999 Assert.AreEqual(1, symbol.
Dim,
"expect a parameter with 1 dimension.");
1000 Assert.AreEqual(0, symbol.
NumberRecords,
"expect a parameter without a record.");
1003 Assert.AreEqual(1000000, count,
"expect 1,000,000 symbols in database.");
1004 logger.Debug(
"exiting TestGAMSDatabase | testAddOneMillionParameters");
1009 public void testAddDatabaseFromNonExistGDXFile()
1011 logger.Debug(
"test exception add db from non existing gdx file");
1018 public void testAddDatabaseFromNullGDXFile()
1020 logger.Debug(
"test exception add db from null gdx file");
1027 public void testAddDatabaseFromGDX()
1029 logger.Debug(
"entering TestGAMSDatabase | testAddDatabaseFromGDX");
1031 String gdxFileName =
"testAddDatabaseFromGDX";
1032 FileInfo dbFile =
new FileInfo(
HouseKeeper.gamsAbsoluteWorkingDir +
1033 Path.DirectorySeparatorChar + gdxFileName +
1035 Assert.False(dbFile.Exists,
"do not expect existence of [" + dbFile.FullName +
"].");
1036 globalDB.
Export(gdxFileName);
1039 Assert.That(dbFile.Exists,
"expect an existence of [" + dbFile.FullName +
"].");
1040 Assert.That(dbFile.Length > 0,
"expect non-empty [" + dbFile.FullName +
"].");
1044 logger.Debug(
"database db added from gdx file [" + gdxFileName +
"]");
1046 Assert.NotNull(db,
"do not expect a NULL GAMSDatabase.");
1047 Assert.NotNull(db.
Name,
"do not expect a NULL database name.");
1048 Assert.AreEqual(db.
NrSymbols, globalDB.
NrSymbols,
"expect same set of symbols in [" + db.
Name +
"] as in [" + globalDB.
Name +
"].");
1051 Assert.NotNull(globalDB.
GetSymbol(symb.
Name),
"expect to find every symbol in [" + db.
Name +
"] from [" + globalDB.
Name +
"]");
1053 Assert.NotNull(db.
GetSymbol(symb.
Name),
"expect to find every symbol in [" + globalDB.
Name +
"] from [" + db.
Name +
"]");
1054 logger.Debug(
"exiting TestGAMSDatabase | testAddDatabaseFromGDX");
1058 public void testGAMSWorkspaceAddDatabseWithSourceDB1()
1060 logger.Debug(
"entering TestGAMSDatabase | testGAMSWorkspaceAddDatabseWithSourceDB1");
1063 Assert.NotNull(db,
"do not expect a NULL GAMSDatabase.");
1064 Assert.NotNull(db.
Name,
"do not expect a NULL database name.");
1065 Assert.AreEqual(db.
NrSymbols, globalDB.
NrSymbols,
"expect same set of symbols in [" + db.
Name +
"] as in [" + globalDB.
Name +
"].");
1068 Assert.NotNull(globalDB.
GetSymbol(symb.
Name),
"expect to find every symbol in [" + db.
Name +
"] from [" + globalDB.
Name +
"]");
1070 Assert.NotNull(db.
GetSymbol(symb.
Name),
"expect to find every symbol in [" + globalDB.
Name +
"] from [" + db.
Name +
"]");
1071 logger.Debug(
"exiting TestGAMSDatabase | testAddDatabaseFromGDX");
1075 public void testGAMSWorkspaceAddDatabseWithSourceDB2()
1077 logger.Debug(
"testGAMSDatabase | testGAMSWorkspaceAddDatabseWithSourceDB2");
1079 String newDBName =
"aNewDatabaseName";
1082 Assert.NotNull(db,
"do not expect a NULL GAMSDatabase.");
1083 Assert.NotNull(db.
Name,
"do not expect a NULL database name.");
1084 Assert.AreEqual(db.
NrSymbols, globalDB.
NrSymbols,
"expect same set of symbols in [" + db.
Name +
"] as in [" + globalDB.
Name +
"].");
1085 logger.Debug(
"exiting TestGAMSDatabase | testGAMSWorkspaceAddDatabseWithSourceDB2");
1089 public void testEquivalentDatabase()
1091 logger.Debug(
"Entering TestGAMSDatabase | testEquivalentDatabase");
1097 Assert.True(db2.Equals(db1));
1101 Assert.True(!db3.Equals(db1));
1105 Assert.True(!db4.Equals(db1));
1108 String testDir = HouseKeeper.gamsWorkingDir + Path.DirectorySeparatorChar +
"testEquivalentDatabase";
1114 Assert.True(!anotherDB.Equals(db1));
1116 logger.Debug(
"Exiting TestGAMSDatabase | testEquivalentDatabase");
1121 logger.Debug(
"entering TestGAMSDatabase | initializeDatabase");
1122 List<String> plants =
new List<String> {
"Seattle",
"San-Francisco",
"San-Diego" };
1123 List<String> markets =
new List<String> {
"New-York",
"Chicago",
"Topeka" };
1125 Dictionary<String, Double> capacity =
new Dictionary<string, double>();
1126 capacity.Add(
"Seattle", 350.0);
1127 capacity.Add(
"San-Diego", 600.0);
1129 Dictionary<String, Double> demand =
new Dictionary<string, double>();
1130 demand.Add(
"New-York", 325.0);
1131 demand.Add(
"Chicago", 300.0);
1132 demand.Add(
"Topeka", 275.0);
1134 Dictionary<String[], Double> distance =
new Dictionary<String[], Double>();
1135 distance.Add(
new String[] {
"Seattle",
"New-York" }, 2.5);
1136 distance.Add(
new String[] {
"Seattle",
"Chicago" }, 1.7);
1137 distance.Add(
new String[] {
"Seattle",
"Topeka" }, 1.8);
1138 distance.Add(
new String[] {
"San-Diego",
"New-York"}, 2.5);
1139 distance.Add(
new String[] {
"San-Diego",
"Chicago" }, 1.8);
1140 distance.Add(
new String[] {
"San-Diego",
"Topeka" }, 1.4);
1144 String iName =
"plants";
1145 String iText =
"canning plants";
1148 Assert.AreEqual(db, i.
GAMSDatabase,
"expect same database reference");
1149 Assert.That(i.
Dim == 1,
"expect plants with one dimension");
1150 Assert.NotNull(i.
Domains,
"do not expect a NULL list object returned");
1151 Assert.That(i.
Domains.Count > 0,
"do not expect an empty list returned.");
1152 Assert.That(iName.Equals(i.
Name),
"except [" + iName +
"] as set name.");
1153 Assert.That(i.
Text.Equals(iText),
"expect [" + iText +
"] as set explanatory text.");
1154 testSymbolWithoutARecord(i, iName);
1155 Assert.AreEqual(1, db.
NrSymbols,
"expect one symbol in db");
1157 foreach (String pl
in plants)
1161 Assert.AreEqual(plants.Count, i1.
NumberRecords,
"expect [" + plants.Count +
"] as a number of plant records.");
1166 Assert.NotNull(record,
"do not expect a NULL set record.");
1170 Assert.AreEqual(1, record.
Keys.Count());
1171 Assert.AreEqual(
"Seattle", record.
Keys[0]);
1174 Assert.AreEqual(1, record.
Keys.Count());
1175 Assert.AreEqual(
"San-Francisco", record.
Keys[0]);
1178 Assert.AreEqual(1, record.
Keys.Count());
1179 Assert.AreEqual(
"San-Diego", record.
Keys[0]);
1184 Assert.AreEqual(3, n,
"expect set [" + i.Name +
"] with 3 iteration records.");
1187 String jName =
"markets";
1188 String jText =
"markets";
1191 Assert.AreEqual(db, j.
GAMSDatabase,
"expect same db reference");
1192 Assert.That(j.
Dim == 1,
"expect plants with one dimension");
1193 Assert.NotNull(j.
Domains,
"do not expect a NULL lust object returned.");
1194 Assert.That(j.
Domains.Count > 0,
"do not expect empty list returned");
1195 Assert.That(jName.Equals(j.
Name));
1196 Assert.That(jText.Equals(j.
Text));
1197 testSymbolWithoutARecord(j, jName);
1198 Assert.AreEqual(2, db.
NrSymbols,
"expect two symbols in db");
1203 Assert.NotNull(sym);
1206 Assert.AreEqual(2, db.NrSymbols);
1207 Assert.AreEqual(db.NrSymbols, count);
1209 foreach (String market
in markets)
1210 j.AddRecord(market);
1216 String cName =
"capacity";
1217 String cText =
"capacity of plant p in cases";
1218 Object[] cdomain =
new Object[] { i };
1223 Assert.That(c.
Dim == 1,
"expect c with one dimension");
1225 Assert.That(c.
Domains.Count > 0);
1226 Assert.That(cName.Equals(c.
Name));
1227 Assert.That(cText.Equals(c.
Text));
1228 testSymbolWithoutARecord(c, cName);
1231 foreach (KeyValuePair<String, Double> entry
in capacity)
1232 c.AddRecord(entry.Key).Value = entry.Value;
1239 String dName =
"demand";
1240 String dText =
"demand at market m in cases";
1241 Object[] ddomain =
new Object[] { j };
1246 Assert.That(d.
Dim == 1);
1248 Assert.That(d.
Domains.Count > 0);
1249 Assert.That(dName.Equals(d.
Name));
1250 Assert.That(dText.Equals(d.
Text));
1251 testSymbolWithoutARecord(d, dName);
1254 foreach (KeyValuePair<String, Double> entry
in demand)
1255 d.AddRecord(entry.Key).Value = entry.Value;
1261 Assert.AreEqual(1, rec.
Keys.Count());
1262 Assert.AreEqual(
"New-York", rec.
Keys[0]);
1265 Assert.AreEqual(1, rec.
Keys.Count());
1266 Assert.AreEqual(
"Topeka", rec.
Keys[0]);
1269 Assert.AreEqual(1, rec.
Keys.Count());
1270 Assert.AreEqual(
"Chicago", rec.
Keys[0]);
1277 Assert.NotNull(symbol);
1284 Assert.AreEqual(4, db.NrSymbols);
1287 Object[] domains =
new Object[] { i, j };
1288 GAMSParameter dist = db.AddParameter(
"distance",
"distance in thousands of miles", domains);
1289 foreach (String[] t
in distance.Keys)
1291 String[] keys =
new String[t.Length];
1292 keys = t.ToArray<String>();
1294 distance.TryGetValue(t, out val);
1297 Assert.AreEqual(6, dist.NumberRecords);
1299 logger.Debug(
"exiting TestGAMSDatabase | initializeDatabase");
1302 private static void testSymbolWithoutARecord(
GAMSSymbol symbol,
string symbolName)
List< GAMSSymbolDomainViolation > ViolRecs
List< GAMSDatabaseDomainViolation > GetDatabaseDVs(int MaxViol=0, int MaxViolPerSym=0)
GAMSVariable GetVariable(string variableIdentifier)
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSSet GetSet(string setIdentifier)
GAMSVariable AddVariable(string identifier, int dimension, VarType varType, string explanatoryText="")
GAMSEquation GetEquation(string equationIdentifier)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Export(string filePath=null)
GAMSSymbol GetSymbol(string symbolIdentifier)
bool SuppressAutoDomainChecking
GAMSEquation AddEquation(string identifier, int dimension, EquType equType, string explanatoryText="")
new GAMSParameterRecord LastRecord()
new GAMSParameterRecord FirstRecord()
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSSetRecord AddRecord(params string[] keys)
GAMSSymbolRecord FirstRecord()
GAMSDatabase GAMSDatabase
GAMSSymbolRecord FindRecord(params string[] keys)
GAMSSymbolRecord LastRecord()
GAMSDatabase AddDatabaseFromGDX(string gdxFileName, string databaseName=null, string inModelName=null)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
static void prepare(String dir)
Prepare directory by checking its existence. If exists, (non - recursively) delete all its contents,...
static bool rcleanup(String dir)
(recursively) delete all contents under dir, and delete dir.
static void initializeTestFrom(String filename, String subdir)
initialize class properties from fileName and prepare directory subdir