public static GTPRegressionResult Test(GTPRegressionPattern pattern, string pInput)
        {
            string lInput = NormalizeInput(pInput);

            if (string.IsNullOrEmpty(lInput))
            {
                return(GTPRegressionResult.FAILED);
            }

            bool lPass = (lInput == "PASS");

            if (!pattern.ParsedSuccessfully)
            {
                return(GTPRegressionResult.FAILED);                     // no pattern found
            }
            if (pattern.IgnoreTest)
            {
                return(GTPRegressionResult.ignore);
            }

            foreach (string lParam in pattern.Parameters)
            {
                int lAt = lParam.IndexOf("!");

                bool lNegate = (lAt >= 0);

                string lParam2 = (lNegate) ? lParam.Substring(lAt + 1) : lParam;

                bool lMatch = (lInput == lParam2);

                if ((!lNegate) && (lMatch))
                {
                    return((!pattern.ExpectFailure) ? GTPRegressionResult.passed : GTPRegressionResult.PASSED);
                }

                if ((lNegate) && (!lMatch) && (!lPass))
                {
                    return((!pattern.ExpectFailure) ? GTPRegressionResult.passed : GTPRegressionResult.PASSED);
                }

                if ((lNegate) && (lMatch))
                {
                    return((!pattern.ExpectFailure) ? GTPRegressionResult.failed : GTPRegressionResult.FAILED);
                }
            }

            return((pattern.ExpectFailure) ? GTPRegressionResult.failed : GTPRegressionResult.FAILED);
        }
Exemplo n.º 2
0
        public void VariousTests()
        {
            RegressionTest[] lRegressionTests =   {
                new RegressionTest( "#? [D17]", "D17", GTPRegressionResult.passed ),
                new RegressionTest( "#? [!D17]", "B8", GTPRegressionResult.passed ),
                new RegressionTest( "#? [B7|D17|X9]", "D17", GTPRegressionResult.passed ),
                new RegressionTest( "#? [!D17]", "D17", GTPRegressionResult.failed ),

                new RegressionTest( "#? [!D17]*", "D17", GTPRegressionResult.FAILED ),
                new RegressionTest( "#? [D17]*", "D17", GTPRegressionResult.PASSED ),
                new RegressionTest( "#? [D17]*", "=8 D17", GTPRegressionResult.PASSED )
            };

            foreach (RegressionTest lRegressionTest in lRegressionTests)
            {
                GTPRegressionPattern lGTPRegressionPattern = new GTPRegressionPattern(lRegressionTest.Pattern);
                GTPRegressionResult lResult = lGTPRegressionPattern.Test(lRegressionTest.Input);

                Assert.AreEqual(lResult, lRegressionTest.ExpectedResult, lRegressionTest.Pattern);
            }
        }
        public void VariousTests()
        {
            RegressionTest[] lRegressionTests =
            {
                new RegressionTest("#? [D17]",       "D17",    GTPRegressionResult.passed),
                new RegressionTest("#? [!D17]",      "B8",     GTPRegressionResult.passed),
                new RegressionTest("#? [B7|D17|X9]", "D17",    GTPRegressionResult.passed),
                new RegressionTest("#? [!D17]",      "D17",    GTPRegressionResult.failed),

                new RegressionTest("#? [!D17]*",     "D17",    GTPRegressionResult.FAILED),
                new RegressionTest("#? [D17]*",      "D17",    GTPRegressionResult.PASSED),
                new RegressionTest("#? [D17]*",      "=8 D17", GTPRegressionResult.PASSED)
            };

            foreach (RegressionTest lRegressionTest in lRegressionTests)
            {
                GTPRegressionPattern lGTPRegressionPattern = new GTPRegressionPattern(lRegressionTest.Pattern);
                GTPRegressionResult  lResult = lGTPRegressionPattern.Test(lRegressionTest.Input);

                Assert.AreEqual(lResult, lRegressionTest.ExpectedResult, lRegressionTest.Pattern);
            }
        }
Exemplo n.º 4
0
        public static GTPRegressionResult Test(GTPRegressionPattern pattern, string pInput)
        {
            string lInput = NormalizeInput(pInput);

            if (string.IsNullOrEmpty(lInput))
                return GTPRegressionResult.FAILED;

            bool lPass = (lInput == "PASS");

            if (!pattern.ParsedSuccessfully)
                return GTPRegressionResult.FAILED;	// no pattern found

            if (pattern.IgnoreTest)
                return GTPRegressionResult.ignore;

            foreach (string lParam in pattern.Parameters)
            {
                int lAt = lParam.IndexOf("!");

                bool lNegate = (lAt >= 0);

                string lParam2 = (lNegate) ? lParam.Substring(lAt + 1) : lParam;

                bool lMatch = (lInput == lParam2);

                if ((!lNegate) && (lMatch))
                    return (!pattern.ExpectFailure) ? GTPRegressionResult.passed : GTPRegressionResult.PASSED;

                if ((lNegate) && (!lMatch) && (!lPass))
                    return (!pattern.ExpectFailure) ? GTPRegressionResult.passed : GTPRegressionResult.PASSED;

                if ((lNegate) && (lMatch))
                    return (!pattern.ExpectFailure) ? GTPRegressionResult.failed : GTPRegressionResult.FAILED;
            }

            return (pattern.ExpectFailure) ? GTPRegressionResult.failed : GTPRegressionResult.FAILED;
        }
Exemplo n.º 5
0
        public static bool ExecuteTest(MemFile memFile, string directory)
        {
            GoBoard lGoBoard = new GoBoard(19);
            GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard);
            GTPCommInternal lGTPCommInternal = new GTPCommInternal();
            GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommInternal);

            lGTPGoBoard.Directory = directory;

            GTPCommand lGTcommand = new GTPCommand("");
            string lInput = string.Empty;

            int[] lRegressionResults = new int[5];

            while (!memFile.EOF)
            {
                string lBuffer = memFile.ReadLine('\n');

                if ((lBuffer.Length >= 4) && (lBuffer.Substring(0, 4) == "quit"))
                    break;

                if ((lBuffer.Length >= 2) && (lBuffer.Substring(0, 2) == "#?"))
                {
                    GTPRegressionPattern lPattern = new GTPRegressionPattern(lBuffer);

                    GTPRegressionResult lRegressionResult = GTPRegressionPattern.Test(lPattern, lInput);

                    lRegressionResults[(int)lRegressionResult]++;

                    switch (lRegressionResult)
                    {
                        case GTPRegressionResult.passed: /* Console.WriteLine("PASSED");*/ break;
                        case GTPRegressionResult.PASSED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected PASS!"); break;
                        case GTPRegressionResult.failed: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " failed: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break;
                        case GTPRegressionResult.FAILED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected failure: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break;
                        case GTPRegressionResult.ignore: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " ignoring '" + lPattern + "', got '" + Proper(lInput) + "'"); break;
                        default: Console.WriteLine("ERROR!!!"); break;
                    }
                }
                else
                    if (lBuffer.Length > 0)
                    {
                        GTPCommand lGTcommand2 = new GTPCommand(lBuffer);

                        if (lGTcommand2.Command.Length != 0)
                        {
                            lGTPCommInternal.SendToEngine(lBuffer);
                            lGTPCommInternal.SendToEngine("\n");

                            lInput = lGTPCommInternal.GetResponse();

                            lGTcommand = lGTcommand2;
                        }
                    }
            }

            for (int lRegressionResultIndex = 0; lRegressionResultIndex < 5; lRegressionResultIndex++)
                Console.WriteLine((GTPRegressionResult)lRegressionResultIndex + " " + lRegressionResults[lRegressionResultIndex]);

            return (lRegressionResults[3] == 0); // false, only for unexpected failures
        }
        public static bool ExecuteTest(MemFile memFile, string directory)
        {
            GoBoard         lGoBoard         = new GoBoard(19);
            GTPGoBoard      lGTPGoBoard      = new GTPGoBoard(lGoBoard);
            GTPCommInternal lGTPCommInternal = new GTPCommInternal();
            GTPEngine       lGTPEngine       = new GTPEngine(lGTPGoBoard, lGTPCommInternal);

            lGTPGoBoard.Directory = directory;

            GTPCommand lGTcommand = new GTPCommand("");
            string     lInput     = string.Empty;

            int[] lRegressionResults = new int[5];

            while (!memFile.EOF)
            {
                string lBuffer = memFile.ReadLine('\n');

                if ((lBuffer.Length >= 4) && (lBuffer.Substring(0, 4) == "quit"))
                {
                    break;
                }

                if ((lBuffer.Length >= 2) && (lBuffer.Substring(0, 2) == "#?"))
                {
                    GTPRegressionPattern lPattern = new GTPRegressionPattern(lBuffer);

                    GTPRegressionResult lRegressionResult = GTPRegressionPattern.Test(lPattern, lInput);

                    lRegressionResults[(int)lRegressionResult]++;

                    switch (lRegressionResult)
                    {
                    case GTPRegressionResult.passed: /* Console.WriteLine("PASSED");*/ break;

                    case GTPRegressionResult.PASSED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected PASS!"); break;

                    case GTPRegressionResult.failed: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " failed: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break;

                    case GTPRegressionResult.FAILED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected failure: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break;

                    case GTPRegressionResult.ignore: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " ignoring '" + lPattern + "', got '" + Proper(lInput) + "'"); break;

                    default: Console.WriteLine("ERROR!!!"); break;
                    }
                }
                else
                if (lBuffer.Length > 0)
                {
                    GTPCommand lGTcommand2 = new GTPCommand(lBuffer);

                    if (lGTcommand2.Command.Length != 0)
                    {
                        lGTPCommInternal.SendToEngine(lBuffer);
                        lGTPCommInternal.SendToEngine("\n");

                        lInput = lGTPCommInternal.GetResponse();

                        lGTcommand = lGTcommand2;
                    }
                }
            }

            for (int lRegressionResultIndex = 0; lRegressionResultIndex < 5; lRegressionResultIndex++)
            {
                Console.WriteLine((GTPRegressionResult)lRegressionResultIndex + " " + lRegressionResults[lRegressionResultIndex]);
            }


            return(lRegressionResults[3] == 0);              // false, only for unexpected failures
        }