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"); }
//Main method public static void Main() { "Testing QueryEngine Package".title('='); Console.WriteLine(); QueryEngine queryv = new QueryEngine(); // new database created for different types DBEngine<int, DBElement<int, string>> newdbq = new DBEngine<int, DBElement<int, string>>(); DBEngine<string, DBElement<string, List<string>>> newdbqs = new DBEngine<string, DBElement<string, List<string>>>(); //new elements created for int ,string database DBElement<int, string> newqelem1 = new DBElement<int, string>(); DBElement<int, string> newqelem2 = new DBElement<int, string>(); DBElement<int, string> newqelem3 = new DBElement<int, string>(); newqelem1.name = "query elemnt 1"; newqelem1.descr = "testing qurey get value for 1"; newqelem1.payload = "new query element payload 1"; newqelem1.children.AddRange(new List<int> { 1, 22, 333 }); newqelem2.name = "query elemnt 2"; newqelem2.descr = "testing query get value for 2"; newqelem2.payload = "new query element payload 2"; newqelem2.children.AddRange(new List<int> { 010, 020, 030 }); newqelem3.name = "query elemnt 3"; newqelem3.descr = "testing quey get value for 3"; newqelem3.payload = "new query element payload 3"; newqelem3.children.AddRange(new List<int> { 777, 222, 333 }); newdbq.insert(1, newqelem1); newdbq.insert(2, newqelem2); newdbq.insert(3, newqelem3); newdbq.showDB(); // testing query 1 DBElement<int, string> displayres = new DBElement<int, string>(); Console.WriteLine("\n \n getting value for key 2"); displayres = queryv.queryvalue<int, DBElement<int, string>, string>(newdbq, 2); if (displayres != null) displayres.showElement(); //testing query 2 Console.WriteLine("\n \n getting children for key 3"); List<int> childlist = new List<int>(); childlist = queryv.querychildren<int, DBElement<int, string>, string>(newdbq, 3); if (childlist != null) { foreach (int i in childlist) Console.WriteLine(i); } //new elements created for string,list of string database DBElement<string, List<string>> newelem1q = new DBElement<string, List<string>>(" element 1", "1 is first"); DBElement<string, List<string>> newelem2q = new DBElement<string, List<string>>(" element 2", "2 is second"); DBElement<string, List<string>> newelem3q = new DBElement<string, List<string>>(" element 3", " 3 is third"); newelem1q.children.AddRange(new List<string> { " one", "one", "one" }); newelem1q.payload = new List<string> { "h", "e", "l", "l", "o" }; newelem2q.children.AddRange(new List<string> { " two", "two", "two" }); newelem2q.payload = new List<string> { "h", "d", "w", "f", "b" }; newelem3q.children.AddRange(new List<string> { " three", "three", "three" }); newelem3q.payload = new List<string> { "a", "e", "i", "o", "u" }; newdbqs.insert("one", newelem1q); newdbqs.insert("two", newelem2q); newdbqs.insert("three", newelem3q); newdbqs.showEnumerableDB(); // testing query one 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>(newdbqs, "two"); if (valuestring != null) valuestring.showEnumerableElement(); //testing query two DBElement<string, List<string>> valuestrings = new DBElement<string, List<string>>(); Console.WriteLine("\n \n getting children for key five"); List<string> childlists = new List<string>(); childlists = queryv.querychildren<string, DBElement<string, List<string>>, string>(newdbqs, "five"); if (childlists != null) { foreach (string cstring in childlists) Console.WriteLine(cstring); } }