Exemple #1
0
        static void Main(string[] args)
        {
            string filename = "test_project.gz";
            string path = "..\\..\\..\\..\\..\\EDSEngine\\EDSEngineTestApp\\" + filename;
            EDSEngine knowledge = new EDSEngine(path);
            if (knowledge.IsOpen() == false)
            {
                knowledge = new EDSEngine(filename);
                if (knowledge.IsOpen() == false)
                {
                    write_result("FAILURE: Could not open rules xml file: " + path);
                    Quit();
                }
            }

            if (knowledge.IsOpen() == true)
                write_result("OK: File opened");

            knowledge.InputGetterDelegate = get_value;

            r = new Random();
            for (int cnt = 0; cnt < TESTCNT; cnt++)
            {
                string color1 = colors1[r.Next(0, 2)];
                string color2 = colors2[r.Next(0, 2)];
                testValues.Add(new KeyValuePair<string, string> [2] { new KeyValuePair<string, string>("Color1", color1), new KeyValuePair<string, string>("Color2", color2) });
            }

            //single threaded result
            TheadStartObject singleThreadedParams = new TheadStartObject() { Rules = knowledge, Messages = _trace };
            TestCycle(singleThreadedParams);
            System.Collections.Concurrent.ConcurrentQueue<string> singleThreadedResults = singleThreadedParams.Results;

            Thread t1 = new Thread(new ParameterizedThreadStart(TestCycle));
            Thread t2 = new Thread(new ParameterizedThreadStart(TestCycle));
            Thread t3 = new Thread(new ParameterizedThreadStart(TestCycle));

            TheadStartObject threadParams1 = new TheadStartObject() { Rules = knowledge, Messages = _trace };
            TheadStartObject threadParams2 = new TheadStartObject() { Rules = knowledge, Messages = _trace };
            TheadStartObject threadParams3 = new TheadStartObject() { Rules = knowledge, Messages = _trace };

            t1.Start(threadParams1);
            t2.Start(threadParams2);
            t3.Start(threadParams3);
            t1.Join();
            t2.Join();
            t3.Join();

            //verify all the results are the same
            var equal1 = singleThreadedParams.Results.SequenceEqual<string>(threadParams1.Results);
            var equal2 = singleThreadedParams.Results.SequenceEqual<string>(threadParams2.Results);
            var equal3 = singleThreadedParams.Results.SequenceEqual<string>(threadParams3.Results);

            var equal = equal1 == true && equal2 == true && equal3 == true;

            write_result("All tests passed: " + equal.ToString());
            write_result("Press 't' key to show trace");
            ConsoleKeyInfo keyInfo = Console.ReadKey();
            if (keyInfo.KeyChar == 't')
                write_trace();
            Quit();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string    filename  = "test_project.gz";
            string    path      = "..\\..\\..\\..\\..\\EDSEngine\\EDSEngineTestApp\\" + filename;
            EDSEngine knowledge = new EDSEngine(path);

            if (knowledge.IsOpen() == false)
            {
                knowledge = new EDSEngine(filename);
                if (knowledge.IsOpen() == false)
                {
                    write_result("FAILURE: Could not open rules xml file: " + path);
                    Quit();
                }
            }

            if (knowledge.IsOpen() == true)
            {
                write_result("OK: File opened");
            }

            knowledge.InputGetterDelegate = get_value;

            r = new Random();
            for (int cnt = 0; cnt < TESTCNT; cnt++)
            {
                string color1 = colors1[r.Next(0, 2)];
                string color2 = colors2[r.Next(0, 2)];
                testValues.Add(new KeyValuePair <string, string> [2] {
                    new KeyValuePair <string, string>("Color1", color1), new KeyValuePair <string, string>("Color2", color2)
                });
            }

            //single threaded result
            TheadStartObject singleThreadedParams = new TheadStartObject()
            {
                Rules = knowledge, Messages = _trace
            };

            TestCycle(singleThreadedParams);
            System.Collections.Concurrent.ConcurrentQueue <string> singleThreadedResults = singleThreadedParams.Results;

            Thread t1 = new Thread(new ParameterizedThreadStart(TestCycle));
            Thread t2 = new Thread(new ParameterizedThreadStart(TestCycle));
            Thread t3 = new Thread(new ParameterizedThreadStart(TestCycle));

            TheadStartObject threadParams1 = new TheadStartObject()
            {
                Rules = knowledge, Messages = _trace
            };
            TheadStartObject threadParams2 = new TheadStartObject()
            {
                Rules = knowledge, Messages = _trace
            };
            TheadStartObject threadParams3 = new TheadStartObject()
            {
                Rules = knowledge, Messages = _trace
            };

            t1.Start(threadParams1);
            t2.Start(threadParams2);
            t3.Start(threadParams3);
            t1.Join();
            t2.Join();
            t3.Join();

            //verify all the results are the same
            var equal1 = singleThreadedParams.Results.SequenceEqual <string>(threadParams1.Results);
            var equal2 = singleThreadedParams.Results.SequenceEqual <string>(threadParams2.Results);
            var equal3 = singleThreadedParams.Results.SequenceEqual <string>(threadParams3.Results);

            var equal = equal1 == true && equal2 == true && equal3 == true;

            write_result("All tests passed: " + equal.ToString());
            write_result("Press 't' key to show trace");
            ConsoleKeyInfo keyInfo = Console.ReadKey();

            if (keyInfo.KeyChar == 't')
            {
                write_trace();
            }
            Quit();
        }