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(); }
static void Main(string[] args) { "Testing ItemEditor Package".title('='); WriteLine(); Write("\n --- Test DBElement<int,string> ---"); // new database created to test the functionaity DBEngine <int, DBElement <int, string> > db = new DBEngine <int, DBElement <int, string> >(); // new elements are created and inserted to the database DBElement <int, string> elem1 = new DBElement <int, string>("first element", "first element description"); DBElement <int, string> elem2 = new DBElement <int, string>("second element", "second element description"); DBElement <int, string> elem3 = new DBElement <int, string>("third element", "third element description"); elem1.payload = "Payload of 1"; elem1.children.AddRange(new List <int> { 1, 2, 3 }); elem2.payload = "Payload of 2"; elem2.children.AddRange(new List <int> { 11, 22, 33 }); elem3.payload = "Payload of 3"; elem3.children.AddRange(new List <int> { 111, 222, 333 }); // inserting elements to database db.insert(1, elem1); db.insert(2, elem2); db.insert(3, elem3); db.showDB(); // testing addition of relationships to elements Write("\n\n Testing of addition of new relationships"); bool addr1 = db.addRelations <int, DBElement <int, string>, string>(1, 2); bool addr2 = db.addRelations <int, DBElement <int, string>, string>(2, 3); bool addr3 = db.addRelations <int, DBElement <int, string>, string>(3, 111); db.showDB(); // testing removing relationships to elements Write("\n\n Testing of removal of relations"); bool remr1 = db.removeRelation <int, DBElement <int, string>, string>(2, 11); bool remr2 = db.removeRelation <int, DBElement <int, string>, string>(1, 3); db.showDB(); if (remr1 && remr2) { Write("\n \n Removal succeded"); } // Testing editing of text data Write("\n\n Testing of editing of text data"); bool ed_name1 = db.editName <int, DBElement <int, string>, string>(1, "renaming of element 1"); bool ed_descr = db.editDescr <int, DBElement <int, string>, string>(1, "editing description of element 1"); bool ed_inst = db.editInstance <int, DBElement <int, string>, string>(1, "new instance for element 1"); db.showDB(); Write("\n\n --- Test DBElement<string,List<string>> ---"); // creating elements to new database of type string,List of strings DBElement <string, List <string> > new_elem1 = new DBElement <string, List <string> >("new element 1", "Description of 1"); DBElement <string, List <string> > new_elem2 = new DBElement <string, List <string> >("new element 2", "Description of 2"); DBElement <string, List <string> > new_elem3 = new DBElement <string, List <string> >("new element 3", "Description of 3"); //creating new database DBEngine <string, DBElement <string, List <string> > > new_db = new DBEngine <string, DBElement <string, List <string> > >(); new_elem1.payload = new List <string> { "First data in payload ", "Second data in payload", "Third data in payload" }; new_elem1.children.AddRange(new List <string> { "one", "two", "three" }); new_elem2.payload = new List <string> { "DP", "SMA", "OOD" }; new_elem2.children.AddRange(new List <string> { "four", "five", "six" }); new_elem3.payload = new List <string> { "CE", "CS", "EE" }; new_elem3.children.AddRange(new List <string> { "seven", "eight", "nine" }); // inserting elements to database new_db.insert("One", new_elem1); new_db.insert("Two", new_elem2); new_db.insert("Three", new_elem3); new_db.showEnumerableDB(); // testing addition of relationships to elements Write("\n\n testing addition of relationship "); bool add1 = new_db.addRelations <string, DBElement <string, List <string> >, List <string> >("One", "two"); bool add2 = new_db.addRelations <string, DBElement <string, List <string> >, List <string> >("Two", "three"); bool add3 = new_db.addRelations <string, DBElement <string, List <string> >, List <string> >("Three", "one"); new_db.showEnumerableDB(); if (add1 && add2 && add3) { Write("\n \n Adding relationship successful."); } // testing removing relationships to elements Write("\n \n Now going to test removing of relationships in DB-element: Element-One"); bool rem1 = new_db.removeRelation <string, DBElement <string, List <string> >, List <string> >("One", "Nine"); bool rem2 = new_db.removeRelation <string, DBElement <string, List <string> >, List <string> >("One", "two"); new_db.showEnumerableDB(); if (rem1 && rem2) { Write("\n \n Deleting of relationships succeeded "); } // Testing editing of text data Write("\n \n Now going to test edition of name, description and replacing instance of payload with new instance in Element-One."); new_db.editName <string, DBElement <string, List <string> >, List <string> >("One", "Edited name for Element-One"); new_db.editDescr <string, DBElement <string, List <string> >, List <string> >("One", "New description for Element-One"); new_db.editInstance <string, DBElement <string, List <string> >, List <string> >("One", new List <string> { "New payload - String One", "New payload - String Two", "New payload - String Three" }); new_db.showEnumerableDB(); 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"); }