Beispiel #1
0
        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");
        }