void TestR2() { "Demonstrating Requirement #2".title(); //creating new element of type int and string DBElement <int, string> element = new DBElement <int, string>(); element.name = "first element of db"; element.descr = "int and string type"; element.timeStamp = DateTime.Now; element.children.AddRange(new List <int> { 0, 2, 4, 8 }); element.payload = "first element's payload"; element.showElement(); db.insert(1, element); db.showDB(); WriteLine(); //creating new element of type string and list of strings DBElement <string, List <string> > element2 = new DBElement <string, List <string> >(); element2.name = "second element of db"; element2.descr = "strings and strings of string types"; element2.timeStamp = DateTime.Now; element2.children.AddRange(new List <string> { "SMA", "OOD", "Project2" }); element2.payload = new List <string> { "second", "SMA", "project" }; element2.showEnumerableElement(); db2.insert("2", element2); db2.showEnumerableDB(); WriteLine(); }
void TestR7() { //Demonstrating queries "Demonstrating Requirement #7".title(); WriteLine(); QueryEngine queryv = new QueryEngine(); DBElement <int, string> displayresc = new DBElement <int, string>(); DBElement <int, string> displayres = new DBElement <int, string>(); //demonstrating query 1 Console.WriteLine("\n \n getting value for key 1"); displayres = queryv.queryvalue <int, DBElement <int, string>, string>(db, 1); if (displayres != null) { displayres.showElement(); } DBElement <string, List <string> > valuestring = new DBElement <string, List <string> >(); Console.WriteLine("\n \n getting value for key 2"); valuestring = queryv.queryvalue <string, DBElement <string, List <string> >, string>(db2, "2"); if (valuestring != null) { valuestring.showEnumerableElement(); } // demonstrating query 2 Console.WriteLine("\n \n getting children for key 1"); List <int> tchildlist = new List <int>(); tchildlist = queryv.querychildren <int, DBElement <int, string>, string>(db, 1); if (tchildlist != null) { foreach (int i in tchildlist) { Console.WriteLine(i); } } }
static void Main(string[] args) { "Testing DBEngine Package".title('=');; WriteLine(); "Test db of scalar elements".title(); WriteLine(); //creation of new elements DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.payload = "X-Wing fighter in swamp - Oh oh!"; if (verbose) { Write("\n --- Test DBElement<int,string> ---"); WriteLine(); elem1.showElement(); WriteLine(); elem2.showElement(); WriteLine(); elem3.showElement(); WriteLine(); } Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); WriteLine(); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; // function to generate keys // new database created DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); bool p1 = db.insert(keyGen(), elem1); bool p2 = db.insert(keyGen(), elem2); bool p3 = db.insert(keyGen(), elem3); if (p1 && p2 && p3) { Write("\n all inserts succeeded"); } else { Write("\n at least one insert failed"); } db.showDB(); WriteLine(); "Test db of enumerable elements".title(); WriteLine(); //new element created DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = new List <string> { "one", "two", "three" }; //new element created DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "better formatting"; newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.Add("delta"); newerelem1.payload.Add("epsilon"); //new element created DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "newerelem2"; newerelem2.descr = "better formatting"; newerelem2.children.AddRange(new List <string> { "first", "second" }); newerelem2.payload = new List <string> { "a", "b", "c" }; newerelem2.payload.Add("d"); newerelem2.payload.Add("e"); if (verbose) { Write("\n --- Test DBElement<string,List<string>> ---"); WriteLine(); newelem1.showEnumerableElement(); WriteLine(); newerelem1.showEnumerableElement(); WriteLine(); newerelem2.showEnumerableElement(); WriteLine(); } Write("\n --- Test DBEngine<string,DBElement<string,List<string>>> ---"); int seed = 0; string skey = seed.ToString(); Func <string> skeyGen = () => { ++seed; skey = "string" + seed.ToString(); skey = skey.GetHashCode().ToString(); return(skey); }; DBEngine <string, DBElement <string, List <string> > > newdb = new DBEngine <string, DBElement <string, List <string> > >(); newdb.insert(skeyGen(), newelem1); newdb.insert(skeyGen(), newerelem1); newdb.insert(skeyGen(), newerelem2); newdb.showEnumerableDB(); Write("\n\n"); }