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(); }
public void TestR2() { "Demonstrating Requirement #2".title('='); "Database with string as payload".title(); DBElement<int, string> elem = new DBElement<int, string>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List<int>{ 1, 2, 3 }); elem.payload = "elem's payload"; elem.showElement(); db.insert(1, elem); db.showDB(); WriteLine(); "database with list of strings as payload".title(); DBElement<string, List<string>> element = new DBElement<string, List<string>>(); element.name = "element2"; element.descr = "test element for list of strings as value"; element.timeStamp = DateTime.Now; element.children.AddRange(new List<string> { "one","two"}); element.payload = new List<string> { "element's payload", "2nd payload" }; element.showEnumerableElement(); enum_db.insert("enum_one", element); enum_db.showEnumerableDB(); WriteLine(); }
/* Defining a query using lambda function to search specific key */ public bool key_value_search(DBEngine<string, DBElement<string, List<string>>> db, out IQuery<string, DBElement<string, List<string>>> i_query, QueryEngine<string, DBElement<string, List<string>>> qe, string key_to_search = "12345") { "Query for value with specified key (key = element2):".title(); WriteLine(); Func<string, string, bool> keyValueSearch = (string key, string search) => //lambda function { if (!db.Keys().Contains(key)) return false; else { if (key == (search)) { DBElement<string, List<string>> ele = new DBElement<string, List<string>>(); db.getValue(key, out ele); return true; } else { return false; } } }; // pass query to query engine and call simpleQuery to make query on DBEngine if (qe.simpleQuery(keyValueSearch, key_to_search.ToString(), out i_query)) { WriteLine(); foreach (var key in i_query.Keys()) { DBElement<string, List<string>> temp = new DBElement<string, List<string>>(); i_query.getValue(key, out temp); WriteLine("key : {0}", key); temp.showEnumerableElement(); WriteLine(); } return true; } else { return false; } }
void TestR3() { WriteLine(); "Demonstrating Requirement #3".title('='); WriteLine(); "Adding Key-Value pair to database".title(); DBElement<int, string> element = new DBElement<int, string>(); element.addElementData("element3", "test element for adding key-value pair to databse with value as string", DateTime.Now, new List<int> { 1, 2 }, "test elemet3's payload"); "element to be added to database".title(); element.showElement(); db.insert(2, element); db.showDB(); WriteLine(); "Adding Key-Value pair to enumerable database".title(); DBElement<string, List<string>> listelement = new DBElement<string, List<string>>(); listelement.addElementData("element4", "test element for adding key-value pair to databse with value as list of string", DateTime.Now, new List<string> { "1", "two" }, new List<string> { "test elemet4's payload" }); "element to be added to database".title(); listelement.showEnumerableElement(); enum_db.insert("enum_two", listelement); enum_db.showEnumerableDB(); WriteLine(); "Deleting Key-Value pair from database".title(); "Element with key=1 will be deleted from database".title(); "Element with key=1:".title(); DBElement<int, string> remove_element = new DBElement<int, string>(); db.getValue(1, out remove_element); remove_element.showElement(); db.remove(1); WriteLine(); "Modified Database: ".title(); db.showDB(); WriteLine(); "Deleting Key-Value pair from enumerable database".title(); "Element with key=enum_one will be deleted from database".title(); "Element with key=enum_one:".title(); DBElement<string, List<string>> remove_enum_element = new DBElement<string, List<string>>(); enum_db.getValue("enum_one", out remove_enum_element); remove_enum_element.showEnumerableElement(); enum_db.remove("enum_one"); WriteLine(); "Modified enumerable Database: ".title(); enum_db.showEnumerableDB(); WriteLine(); }
public void TestR7() { "Demonstrating Requirement #7".title('='); WriteLine(); "Adding elements to db".title(); WriteLine(); for (int i = 0; i < 3; i++) { DBElement<string, List<string>> elem = new DBElement<string, List<string>>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = new DateTime(2015,10,(2+i)); elem.children.AddRange(new List<string> { "one", "two", "three" }); elem.payload = new List<string>{ "elem's payload1","payload2","payload 3"}; elem.showEnumerableElement(); WriteLine(); enum_db.insert((12345+i).ToString(), elem); } "current DB status:".title(); enum_db.showEnumerableDB(); IQuery<string, DBElement<string, List<string>>> i_query = new DBEngine<string, DBElement<string, List<string>>>(); QueryEngine<string, DBElement<string, List<string>>> qe = new QueryEngine<string, DBElement<string, List<string>>>(enum_db); QueryPredicate qp = new QueryPredicate(); qp.key_value_search(enum_db, out i_query, qe); WriteLine(); qp.key_children_search(enum_db, out i_query, qe); WriteLine(); qp.pattern_matching(enum_db, out i_query, qe, "12345"); WriteLine(); qp.pattern_matching(enum_db, out i_query, qe); WriteLine(); qp.metadata_string(enum_db, out i_query, qe); WriteLine(); DateTime start = new DateTime(2015, 10, 4); DateTime end = new DateTime(2015, 10, 5); qp.date_time_specific(enum_db, out i_query, qe, start, end); WriteLine(); qp.default_date_time_specific(enum_db, out i_query, qe, start); WriteLine(); }
void TestR4(string edit_action) { DBElement<string, List<string>> element = new DBElement<string, List<string>>(); element.addElementData("element1", "test element for editing key-value pair to databse with value as string", DateTime.Now, new List<string> { "enum_one", "enum_two" }, new List<string> { "test element1's payload" }); enum_db.insert("enum_one", element); "Demonstrating Requirement #4".title(); DBElement<string, List<string>> edit_element = new DBElement<string, List<string>>(); enum_db.getValue("enum_one", out edit_element); "Element to be edited".title(); edit_element.showEnumerableElement(); WriteLine(); "Database before editing".title(); enum_db.showEnumerableDB(); WriteLine(); switch (edit_action) { case "edit metadata": edit_element.edit_metadata(edit_action); goto default; case "add children": edit_element.add_children(edit_action); goto default; case "remove children": edit_element.remove_children(edit_action); goto default; case "edit payload": edit_element.edit_payload(); goto default; default: "element after editing".title(); edit_element.showEnumerableElement(); "Databaser after editing".title(); enum_db.showEnumerableDB(); WriteLine(); break; } }
static void Main(string[] args) { "Testing DBEngine Package".title('=');; WriteLine(); "Test db of scalar elements".title(); WriteLine(); 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(); /* ElementFormatter is not ready for prime time yet */ //Write(ElementFormatter.formatElement(elem1.showElement<int, string>(), false)); } Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); WriteLine(); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; 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(); 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" }; 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"); 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"); }
public static void Main() { "Testing QueryEngine Package".title('='); Console.WriteLine(); QueryEngine queryv = new QueryEngine(); 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> > >(); 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(); 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(); } 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); } } 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(); 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(); } 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); } } }
/* Defining a query using lambda function to search specific elements belonging in specific * time-interval with end of time interval equal to present */ public void date_time_specific(DBEngine<string, DBElement<string, List<string>>> db, out IQuery<string, DBElement<string, List<string>>> i_query, QueryEngine<string, DBElement<string, List<string>>> qe, DateTime start, DateTime end = new DateTime()) { "Query for keys with specified date time interval: start=10/4/2015 end=10/5/2015".title(); WriteLine(); Func<string, DateTime, DateTime, bool> TimeDateQuery = (string key, DateTime query_start, DateTime query_end) => //lambda function { if (!db.Keys().Contains(key)) return false; else { DBElement<string, List<string>> ele = new DBElement<string, List<string>>(); db.getValue(key, out ele); int start_result = DateTime.Compare(query_start, ele.timeStamp); int end_result = DateTime.Compare(query_end, ele.timeStamp); if ((start_result <= 0) && (end_result >= 0)) { return true; } else return false; } }; // pass query to query engine and call simpleQuery to make query on DBEngine qe.simpleQueryDate(TimeDateQuery, out i_query, start, end); WriteLine(); foreach (var key in i_query.Keys()) { DBElement<string, List<string>> temp = new DBElement<string, List<string>>(); i_query.getValue(key, out temp); WriteLine("key : {0}", key); temp.showEnumerableElement(); WriteLine(); } }
/* Defining a query using lambda function to search specific string in metadata */ public bool metadata_string(DBEngine<string, DBElement<string, List<string>>> db, out IQuery<string, DBElement<string, List<string>>> i_query, QueryEngine<string, DBElement<string, List<string>>> qe, string metadata_str = "ele") { "Query for specified string in metadata: String = 'ele' ".title(); WriteLine(); Func<string, string, bool> stringMetadata = (string key, string search) => //lambda function { if (!db.Keys().Contains(key)) return false; else { DBElement<string, List<string>> ele = new DBElement<string, List<string>>(); db.getValue(key, out ele); if (ele.name.Contains(search) || ele.descr.Contains(search)) return true; else return false; } }; // pass query to query engine and call simpleQuery to make query on DBEngine if (qe.simpleQuery(stringMetadata, metadata_str, out i_query)) { WriteLine(); foreach (var key in i_query.Keys()) { DBElement<string, List<string>> temp = new DBElement<string, List<string>>(); i_query.getValue(key, out temp); WriteLine("key : {0}", key); temp.showEnumerableElement(); WriteLine(); } return true; } else { return false; } }
/* Defining a query using lambda function to search specific key matching default pattern */ public void default_pattern_matching(DBEngine<string, DBElement<string, List<string>>> db, out IQuery<string, DBElement<string, List<string>>> i_query, QueryEngine<string, DBElement<string, List<string>>> qe) { string pattern = ""; "Query for keys matching with specified pattern (pattern = none -> default case):".title(); WriteLine(); Func<string, string, bool> keysMatchingPattern = (string key, string search) => //lambda function { if (!db.Keys().Contains(key)) return false; else { if (key.ToString().Contains(search)) { DBElement<string, List<string>> ele = new DBElement<string, List<string>>(); db.getValue(key, out ele); return true; } else return false; } }; // pass query to query engine and call simpleQuery to make query on DBEngine qe.simpleQuery(keysMatchingPattern, pattern, out i_query); WriteLine(); foreach (var key in i_query.Keys()) { DBElement<string, List<string>> temp = new DBElement<string, List<string>>(); i_query.getValue(key, out temp); WriteLine("key : {0}", key); temp.showEnumerableElement(); WriteLine(); } }
private void display_children(IQuery<string, DBElement<string, List<string>>> i_query, DBEngine<string, DBElement<string, List<string>>> db) { foreach (var key in i_query.Keys()) { DBElement<string, List<string>> temp = new DBElement<string, List<string>>(); i_query.getValue(key, out temp); WriteLine("children of element with key {0} :", key); WriteLine(); if (temp.children != null) { int i = 0; foreach (string child in temp.children) { WriteLine("Children {0}", ++i); DBElement<string, List<string>> temp_child = new DBElement<string, List<string>>(); if (db.Keys().Contains(child)) { db.getValue(child, out temp_child); WriteLine("key : {0}", child); temp_child.showEnumerableElement(); WriteLine(); } else { WriteLine("no value with key {0} is present in database", child); WriteLine(); } } } } }
void TestR12() { try { "\nThe database is shown below:".title(); WriteLine("\n Key: Apple"); DBElement<string, List<string>> elem1 = new DBElement<string, List<string>>(); elem1.name = "Apple"; elem1.descr = "Type of fruit"; elem1.timeStamp = DateTime.Now; elem1.children.AddRange(new List<string> { "three" }); elem1.payload = new List<string> { "Seven" }; elem1.category = new List<string> { "fruit", "drink" }; dbCategory.insert("Apple", elem1); elem1.showEnumerableElement(); displayCategory(elem1.category); WriteLine("\n Key: Banana"); DBElement<string, List<string>> elem2 = new DBElement<string, List<string>>(); elem2.name = "Banana"; elem2.descr = "Type of fruit"; elem2.timeStamp = DateTime.Now; elem2.children.AddRange(new List<string> { "two" }); elem2.payload = new List<string> { "Five", "Six" }; elem2.category = new List<string> { "fruit" }; dbCategory.insert("Banana", elem2); elem2.showEnumerableElement(); displayCategory(elem2.category); WriteLine("\n Key: Blackberry"); DBElement<string, List<string>> elem3 = new DBElement<string, List<string>>(); elem3.name = "Blackberry"; elem3.descr = "Type of fruit or phone"; elem3.timeStamp = DateTime.Now; elem3.children.AddRange(new List<string> { "one" }); elem3.payload = new List<string> { "Eight" }; elem3.category = new List<string> { "fruit", "phone" }; dbCategory.insert("Blackberry", elem3); elem3.showEnumerableElement(); displayCategory(elem3.category); dictCategory = new Dictionary<string, List<string>>(); dictCategory.Add("fruit", new List<string> { "Apple", "Banana" }); List<string> values = new List<string>(); dictCategory.TryGetValue("fruit", out values); dynamic result = qEngine.getKeyForCategory(dbCategory, values); "\nMatched keys for category 'fruit'".title(); displayStringKeys(result); } catch (Exception e) { WriteLine("\n" + e.Message + "\n"); } }
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) { //<------Create test DB-----> "Testing for PersistEngine package".title(); DBEngine<int, DBElement<int, string>> db = new DBEngine<int, DBElement<int, string>>(); DBEngine<string, DBElement<string, List<string>>> enum_db = new DBEngine<string, DBElement<string, List<string>>>(); for (int i = 0; i < 3; i++) { DBElement<int, string> elem = new DBElement<int, string>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List<int> { 1, 2, 3 }); elem.payload = "elem's payload"; elem.showElement(); db.insert(i, elem); } db.showDB(); WriteLine(); //<-------Save DB data to XML file---------> "Demonstrating XDocument class".title('='); WriteLine(); "Creating XML string using XDocument".title(); WriteLine(); db.create_xml_from_db(false); //<---Empty DBEngine<int, DBElement<int, string>>---> "Removing entries from Db if any".title(); if (db != null) { db.removeAll(); } "Current DB state".title(); db.showDB(); WriteLine(); db.create_db_from_xml(); WriteLine(); //<---------Create test enum DB--------> for (int i = 0; i < 3; i++) { DBElement<string, List<string>> elem = new DBElement<string, List<string>>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List<string> { "child1", "child2" }); elem.payload = new List<string> { "payload 1", "payload 2" }; elem.showEnumerableElement(); enum_db.insert(i.ToString(), elem); } enum_db.showEnumerableDB(); WriteLine(); //<-------Save enum_DB data to XML file---------> "Creating XML string using XDocument".title(); enum_db.create_xml_from_enum_db(false); WriteLine(); if (enum_db != null) { enum_db.removeAll(); } //<----Empty DBEngine<string, DBElement<string, List<string>>-----> "Removing entries from enum Db if any".title(); if (enum_db != null) { string[] key_array = enum_db.Keys().ToArray(); foreach (string key in key_array) { enum_db.remove(key); } } "Cureent enum DB state".title(); enum_db.showEnumerableDB(); WriteLine(); enum_db.create_enum_db_from_xml(); WriteLine(); WriteLine(); }
static void Main(string[] args) { DBEngine<string, DBElement<string, List<string>>> db = new DBEngine<string, DBElement<string, List<string>>>(); for (int i = 0; i < 3; i++) { DBElement<string, List<string>> elem = new DBElement<string, List<string>>(); elem.name = "element"; elem.descr = "test element"; elem.timeStamp = new DateTime(2015, 10, (2 + i)); elem.children.AddRange(new List<string> { "element1", "element2", "element3" }); elem.payload = new List<string> { "elem's payload1", "elem's payload2" }; elem.showEnumerableElement(); WriteLine(); db.insert("element"+(12345 + i).ToString(), elem); } for (int i = 0; i < 3; i++) { DBElement <string, List<string>> elem = new DBElement<string, List<string>>(); elem.name = "db data"; elem.descr = "db data description"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List<string> { "element12345", "element12346", "element12347" }); elem.payload = new List<string> { "elem's payload1", "elem's payload2" }; elem.showEnumerableElement(); WriteLine(); db.insert("element"+(i+1).ToString(), elem); } IQuery<string, DBElement<string, List<string>>> i_query = new DBEngine<string, DBElement<string, List<string>>>(); QueryEngine<string, DBElement<string, List<string>>> qe = new QueryEngine<string, DBElement<string, List<string>>>(db); //<---- creating a query predicate object and calling each query on given test database ---> QueryPredicate qp = new QueryPredicate(); qp.key_value_search(db, i_query, qe); WriteLine(); qp.key_children_search(db, i_query, qe); WriteLine(); qp.pattern_matching(db, i_query, qe); WriteLine(); qp.default_pattern_matching(db, i_query, qe); WriteLine(); qp.metadata_string(db, i_query, qe); WriteLine(); qp.date_time_specific(db, i_query, qe); WriteLine(); qp.default_date_time_specific(db, i_query, qe); WriteLine(); }
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"); }
private static void Test2(out DBElement<string, string> newelem1, out DBElement<string, string> newerelem1, out DBElement<string, string> newerelem2) { newelem1 = new DBElement<string, string>(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.payload = "one"; //Load the second element newerelem1 = new DBElement<string, string>(); newerelem1.name = "newerelem1"; newerelem1.descr = "better formatting"; newerelem1.payload = "alpha"; //Load the third element newerelem2 = new DBElement<string, string>(); newerelem2.name = "newerelem2"; newerelem2.descr = "better formatting"; newerelem2.children.AddRange(new List<string> { "first", "second" }); newerelem2.payload = "a"; if (verbose) { Write("\n --- Test DBElement<string,List<string>> ---"); WriteLine(); newelem1.showEnumerableElement(); //Display the element WriteLine(); newerelem1.showEnumerableElement(); //Display the element WriteLine(); newerelem2.showEnumerableElement(); WriteLine(); } }