static void Main(string[] args) { "Testing DBElement Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); WriteLine(); DBElement <int, string> elem1 = new DBElement <int, string>(); Write(elem1.showElement <int, string>()); WriteLine(); DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; Write(elem2.showElement <int, string>()); WriteLine(); var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.children = new List <int> { 1, 2, 7 }; elem3.payload = "X-Wing fighter in swamp - Oh oh!"; Write(elem3.showElement <int, string>()); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); 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" }; Write(newelem1.showElement <string, List <string>, string>()); WriteLine(); DBElement <string, List <string> > newerelem1 = new DBElement <string, List <string> >(); newerelem1.name = "newerelem1"; newerelem1.descr = "same stuff"; newerelem1.children.Add("first_key"); newerelem1.children.Add("second_key"); newerelem1.payload = new List <string> { "alpha", "beta", "gamma" }; newerelem1.payload.AddRange(new[] { "delta", "epsilon" }); Write(newerelem1.showElement <string, List <string>, string>()); WriteLine(); Write("\n\n"); }
//----< write simple db elements out to Console >------------------ public static void show <Key, Value, Data>(this DBEngine <Key, Value> db) { foreach (Key key in db.Keys()) { Value value; db.getValue(key, out value); DBElement <Key, Data> elem = value as DBElement <Key, Data>; Write("\n\n -- key = {0} --", key); Write(elem.showElement()); } }
//-------------< Following is the demonstration of each requirement, for each database type >---------- void TestR2() { //----< Demonstrating the structure of each element of the database. Taking only <int, string> for now >------- "Demonstrating Requirement #2".title('-'); WriteLine(); "Element Structure (Key=int, Value=DBElement<int, string>)".title('-'); DBElement<int, string> elem = new DBElement<int, string>(); elem.name = "Test Element"; elem.descr = "Description"; elem.timeStamp = DateTime.Now; elem.children.Add(5); elem.payload = "Hello!"; Write(elem.showElement<int, string>()); WriteLine(); db.insert(0, elem); }
void TestR2() { "Demonstrating Requirement #2".title(); Write("\n --- When the instance is string --- \n"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.showElement(); dbInt.insert(1, elem1); dbInt.showDB(); WriteLine(); Write("\n --- When the instance is a list of string ---"); DBElement <string, List <string> > elem2 = new DBElement <string, List <string> >(); elem2.name = "elementLos1"; elem2.descr = "element with ListofStrings payload"; elem2.timeStamp = new DateTime(2015, 9, 29, 12, 0, 0); elem2.payload = new List <string> { "one", "two", "three", "four", "five" }; elem2.showElement(); DBListOfString.insert("key15", elem2); DBElement <string, List <string> > elem3 = new DBElement <string, List <string> >(); elem3.name = "elemLos2"; elem3.descr = "element with ListOfString payload"; elem3.timeStamp = new DateTime(2015, 10, 2, 10, 0, 0); elem3.children = new List <string> { "key1", "key2", "key3" }; elem3.payload = new List <string> { "alpha", "beta", "gamma", "delta", "epsilon" }; elem3.showElement(); DBListOfString.insert("key16", elem3); DBListOfString.showEnumerableDB(); WriteLine(); }
static void Main(string[] args) { "Testing DBExtensions Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; Write(elem1.showElement <int, string>()); DBEngine <int, DBElement <int, string> > dbs = new DBEngine <int, DBElement <int, string> >(); dbs.insert(1, elem1); dbs.show <int, DBElement <int, string>, string>(); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); DBElement <string, List <string> > newelem1 = new DBElement <string, List <string> >(); newelem1.name = "newelem1"; newelem1.descr = "test new type"; newelem1.children = new List <string> { "Key1", "Key2" }; newelem1.payload = new List <string> { "one", "two", "three" }; Write(newelem1.showElement <string, List <string>, string>()); DBEngine <string, DBElement <string, List <string> > > dbe = new DBEngine <string, DBElement <string, List <string> > >(); dbe.insert("key1", newelem1); dbe.show <string, DBElement <string, List <string> >, List <string>, string>(); Write("\n\n"); }
static void Main(string[] args) { "Testing DBEngine Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); DBElement <int, string> elem1 = new DBElement <int, string>(); elem1.payload = "a payload"; Write(elem1.showElement <int, string>()); WriteLine(); DBElement <int, string> elem2 = new DBElement <int, string>("Darth Vader", "Evil Overlord"); elem2.payload = "The Empire strikes back!"; Write(elem2.showElement <int, string>()); WriteLine(); var elem3 = new DBElement <int, string>("Luke Skywalker", "Young HotShot"); elem3.children.AddRange(new List <int> { 1, 5, 23 }); elem3.payload = "X-Wing fighter in swamp - Oh oh!"; Write(elem3.showElement <int, string>()); WriteLine(); Write("\n --- Test DBEngine<int,DBElement<int,string>> ---"); int key = 0; Func <int> keyGen = () => { ++key; return(key); }; // anonymous function to generate keys 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.show <int, DBElement <int, string>, string>(); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); 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" }; Write(newelem1.showElement <string, List <string> >()); WriteLine(); Write("\n --- Test DBElement<string,List<string>> ---"); 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"); Write(newerelem1.showElement <string, List <string>, string>()); WriteLine(); DBElement <string, List <string> > newerelem2 = new DBElement <string, List <string> >(); newerelem2.name = "newerelem2"; newerelem2.descr = "better formatting"; newerelem1.children.AddRange(new[] { "first", "second" }); newerelem2.payload = new List <string> { "a", "b", "c" }; newerelem2.payload.Add("d"); newerelem2.payload.Add("e"); Write(newerelem2.showElement <string, List <string>, string>()); 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(), newerelem1); newdb.insert(skeyGen(), newerelem2); newdb.show <string, DBElement <string, List <string> >, List <string>, string>(); WriteLine(); "testing edits".title(); db.show <int, DBElement <int, string>, string>(); DBElement <int, string> editElement = new DBElement <int, string>(); db.getValue(1, out editElement); editElement.showElement <int, string>(); editElement.name = "editedName"; editElement.descr = "editedDescription"; db.show <int, DBElement <int, string>, string>(); WriteLine(); Write("\n\n"); "testing removal".title(); db.show <int, DBElement <int, string>, string>(); DBElement <int, string> pay = new DBElement <int, string>(); db.remove(1, out pay); Console.Write("\n\nRemoved element: {0}", pay.name); WriteLine(); newdb.show <string, DBElement <string, List <string> >, List <string>, string>(); db.show <int, DBElement <int, string>, string>(); Write("\n\n"); }
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 showEnumerableElement(this DBElement <string, List <string> > enumElement) { Console.Write(enumElement.showElement <string, List <string>, string>()); }
public static void showElement(this DBElement <int, string> element) { Console.Write(element.showElement <int, string>()); }
void TestR3() { //----------< Demonstrating adding and removing of elements >----------- "Demonstrating Requirement #3".title(); WriteLine(); "Adding <int, string> elements".title('-'); DBElement<int, string> elem = new DBElement<int, string>(); elem.name = "Element 1"; elem.descr = "Test Element (int, string)"; elem.timeStamp = DateTime.Now; elem.children.AddRange(new List<int> { 1, 2, 3 }); elem.payload = "Element 1's payload. (string)"; WriteLine(elem.showElement()); bool p1 = db.insert(1, elem); WriteLine(); DBElement<int, string> elem1 = new DBElement<int, string>(); elem1.name = "Element 2"; elem1.descr = "Again <int, string> but no children!"; elem1.timeStamp = DateTime.Now; elem1.children.Clear(); elem1.payload = "Element 2's payload. (string)"; WriteLine(elem1.showElement()); bool p2 = db.insert(2, elem1); WriteLine(); DBElement<int, string> elem2 = new DBElement<int, string>(); elem2.name = "Element 3"; elem2.descr = "Test Element <int, string>. Different timeStamp."; elem2.children.AddRange(new List<int> { 1, 2, 3 }); elem2.timeStamp = DateTime.UtcNow; elem2.payload = "Element 3's payload. (string)"; WriteLine(elem2.showElement()); WriteLine(); bool p3 = db.insert(3, elem2); "Adding <string, List<string>> elements".title('-'); DBElement<string, List<string>> newelem = new DBElement<string, List<string>>(); newelem.name = "New elem"; newelem.descr = "Element 4. <string, List<string>>"; newelem.timeStamp = DateTime.Now; newelem.children.AddRange(new List<string> { "one", "two", "three" }); newelem.payload = new List<string> { "one", "two", "three" }; Write(newelem.showElement<string, List<string>, string>()); bool p4 = dbLOS.insert("Four", newelem); Console.WriteLine("\n\nInserting elements... "); if (p1 && p2 && p3 && p4) Console.WriteLine("All inserts succeeded"); else Console.WriteLine("\n\nAt Least one insert failed"); "Database".title('-'); db.show<int, DBElement<int, string>, string>(); dbLOS.show<string, DBElement<string, List<string>>, List<string>, string>(); WriteLine(); "Removing elements".title(); DBElement<int, string> pay = new DBElement<int, string>(); db.remove(1, out pay); Console.Write("\n\nRemoved element: {0}", pay.name); WriteLine(); db.remove(2, out pay); Console.Write("\n\nRemoved element: {0}", pay.name); WriteLine(); db.remove(3, out pay); Console.Write("\n\nRemoved element: {0}", pay.name); WriteLine(); "Database".title(); db.show<int, DBElement<int, string>, string>(); dbLOS.show<string, DBElement<string, List<string>>, List<string>, string>(); WriteLine(); }