コード例 #1
0
ファイル: Program.cs プロジェクト: L-Dogg/ASD2
        public TestResult TestCrossoutsNumber(out string message)
        {
            DateTime t1 = DateTime.Now;
            int      b;

            CrossoutChecker_rozw.Erasable(sequence, patterns, out b);
            if (crossoutNumber == null)
            {
                crossoutNumber = b;
            }
            TimeSpan   ts = DateTime.Now - t1;
            bool       res;
            int        w   = -1;
            TestResult ret = TestResult.OK;
            string     msg = "OK";
            Thread     th  = new Thread(() =>
            {
                if (catchExceptions)
                {
                    try
                    {
                        res = CrossoutChecker.Erasable(sequence, patterns, out w);
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception)
                    {
                        ret = TestResult.Exception;
                        msg = "Wyjatek!";
                        return;
                    }
                }
                else
                {
                    res = CrossoutChecker.Erasable(sequence, patterns, out w);
                }
                if (w != crossoutNumber)
                {
                    ret = TestResult.BadCrossoutsNumber;
                    msg = "BLAD: jest " + w.ToString() + " a powinno byc " + crossoutNumber.ToString();
                }
            });

            th.Start();
            if (!th.Join((int)(ts.TotalMilliseconds * mercyConstant) + 50))
            {
                ret = TestResult.Timeout;
                msg = "Timeout!";
                th.Abort();
            }
            th.Join();
            message = msg;
            return(ret);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: L-Dogg/ASD2
        public TestResult TestMinimumRemainder(out string message)
        {
            DateTime t1 = DateTime.Now;
            int      x  = CrossoutChecker_rozw.MinimumRemainder(sequence, patterns);

            if (minimumRemainder == null)
            {
                minimumRemainder = x;
            }
            TimeSpan   ts  = DateTime.Now - t1;
            int        w   = -1;
            TestResult ret = TestResult.OK;
            string     msg = "OK";
            Thread     th  = new Thread(() =>
            {
                if (catchExceptions)
                {
                    try
                    {
                        w = CrossoutChecker.MinimumRemainder(sequence, patterns);
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception)
                    {
                        ret = TestResult.Exception;
                        msg = "Wyjatek!";
                        return;
                    }
                }
                else
                {
                    w = CrossoutChecker.MinimumRemainder(sequence, patterns);
                }
                if (w != minimumRemainder)
                {
                    ret = TestResult.BadMinimumRemainder;
                    msg = "BLAD: jest " + w.ToString() + " a powinno byc " + minimumRemainder.ToString();
                }
            });

            th.Start();
            if (!th.Join((int)(ts.TotalMilliseconds * mercyConstant) + 50))
            {
                ret = TestResult.Timeout;
                msg = "Timeout!";
                th.Abort();
            }
            th.Join();
            message = msg;
            return(ret);
        }