Пример #1
0
        public void Find()
        {
            IEnumerable <string> words = WordListLoader.Load(
                @"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt")
                                         .Where(w => w.Length >= 3 &&
                                                Regex.IsMatch(w.ToString(), @"^[a-z]+$"));

            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            TestTimer tt = new TestTimer();

            tt.Start();

            List <string> matches = AnagramEngine.Find("webster", words.ToList());

            Console.Write("webster" + " - ");

            foreach (var match in matches)
            {
                Console.Write(match + " ");
            }

            tt.Start();
            Console.WriteLine(tt.ElapsedMilliseconds);

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);

            //600 - 700 list

            //450 - 550
        }
Пример #2
0
        public static void RunTestHelper(ITest test)
        {
            test.Result.Status = TestStatus.Pass;
            TestTimer timer = new TestTimer();

            try
            {
                timer.Start(test);
                test.TestMethod.Invoke(test.Fixture.Instance, null);
                timer.Stop();
            }
            catch (TargetInvocationException tie)
            {
                timer.Stop();
                Exception exp = tie.InnerException;
                test.Result.Status = TestStatus.Fail;
                test.Result.Message.AppendLine(exp.Message);
                test.Result.Message.Append("EXCEPTION TYPE: ");
                test.Result.Message.AppendLine(exp.GetType().FullName);
                test.Result.SetFilteredStackTrace(exp.StackTrace);
            }
            finally
            {
                timer.Stop();
            }
        }
Пример #3
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            if (UuIdText.Enabled)
            {
                return;
            }

            LogText.Clear();
            stopwatch.Restart();

            StartButton.Enabled         = false;
            ClearUuIdTextButton.Enabled = false;
            StopButton.Enabled          = true;
            TestInfoButton.Enabled      = true;

            try
            {
                if (Cache.CacheObjects
                    .SolvedTestSessions
                    .Where(session => session.Value.UuId == UuIdText.Text)
                    .Count() == 1)
                {
                    var solvedSession = Cache.CacheObjects
                                        .SolvedTestSessions
                                        .First(session => session.Value.UuId == UuIdText.Text);

                    FinderSystem_OnDocumentIsFound(null, new OnTestDocumentIsFoundArgs(solvedSession.Key, solvedSession.Value));
                }
                else
                {
                    if (finderSystem is null)
                    {
                        finderSystem = new FinderSystem(client, UuIdText.Text, threadsCount, finderIterationsCount);
                        finderSystem.OnNewDocument     += FinderSystem_OnNewDocument;
                        finderSystem.OnDocumentIsFound += FinderSystem_OnDocumentIsFound;
                        finderSystem.OnError           += FinderSystem_OnError;

                        finderSystem.Start();
                    }
                    else
                    {
                        finderSystem.Restart(UuIdText.Text);
                    }
                }
            }
            catch (Exception exception)
            {
                OnFatalError(exception);
            }

            var testSession = finderSystem.GetTestSession();

            if (testSession != null && testSession.Duration.HasValue)
            {
                splitContainer2.Panel2.Enabled = true;
                TestTimer.Start();
            }
        }
Пример #4
0
 private void RestartTimer()
 {
     while (TestTimer.Enabled)
     {
         Thread.Sleep(10000);
     }
     ChangeControlStatus(buttonStartDaemon, false);
     TestTimer.Start();
 }
        public FsCheckRunner(
            IRunner runnerImplementation, FsCheckRunnerConfig csharpRunnerConfig,
            CSharpNotationConfig csharpNotationConfig, int?maxTest)
        {
            RunnerImplementation = runnerImplementation;
            FsCheckRunnerConfig  = csharpRunnerConfig ?? FsCheckRunnerConfig.Default;
            CSharpNotationConfig = csharpNotationConfig ?? CSharpNotationConfig.Default;
            MaxTest = maxTest ?? FsCheckConfig.Default.MaxTest;

            TestTimer.Start();
        }
Пример #6
0
 public Menu()
 {
     InitializeComponent();
     TestTimer.Start();
     PanelEmployees.Visible = false;
     PanelClients.Visible   = false;
     PanelWarehouse.Visible = false;
     PanelProducts.Visible  = false;
     PanelGoods.Visible     = false;
     PanelDispatch.Visible  = false;
     PanelAccepted.Visible  = false;
 }
Пример #7
0
        public void SimulatePassageOfTime_WaitLessThanOneEvent_DoesNotExecuteEvent()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(1000);
            timer.SimulateTime(999);
            timer.Stop();

            _numberOfExecutions.Should().Be(0);
        }
Пример #8
0
        public Form1()
        {
            InitializeComponent();

            Engine.Core.Engine engine = new Engine.Core.Engine();

            Engine.Core.Scoring.StartEngine(engine);

            MouseDown += Form1_MouseDown1;
            Location   = new Point(0, 0);
            TestTimer.Start();
        }
Пример #9
0
        public void SimulatePassageOfTime_Wait_ExecutesCorrectAmountOfEvents(int timeBetweenEvents, int timeToWait, int expectedAmountOfExecuted)
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(timeBetweenEvents);
            timer.SimulateTime(timeToWait);
            timer.Stop();

            _numberOfExecutions.Should().Be(expectedAmountOfExecuted);
        }
Пример #10
0
        /// <summary>
        /// Executes the inner test method, gathering the amount of time it takes to run.
        /// </summary>
        /// <returns>Returns information about the test run</returns>
        public override MethodResult Execute(object testClass)
        {
            TestTimer timer = new TestTimer();

            timer.Start();
            MethodResult methodResult = InnerCommand.Execute(testClass);
            timer.Stop();

            methodResult.ExecutionTime = timer.ElapsedMilliseconds / 1000.00;

            return methodResult;
        }
Пример #11
0
        public void SimulatePassageOfTime_WaitMoreThanOneEventButLessThanTwo_ExecutesOnesEvent(int timeBetweenEvents, int timeToWait)
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(timeBetweenEvents);
            timer.SimulateTime(timeToWait);
            timer.Stop();

            _numberOfExecutions.Should().Be(1);
        }
Пример #12
0
        public void SimulatePassageOfTime_WaitExactlyForOneEvent_ExecutesOneEvent()
        {
            var timer = new TestTimer();

            timer.Elapsed += ActionToPerform;

            timer.Start(1000);
            timer.SimulateTime(1000);
            timer.Stop();

            _numberOfExecutions.Should().Be(1);
        }
        /// <summary>
        /// This method is called by the test object to invoke the test.
        /// </summary>
        /// <param name="test">The calling test object.</param>
        public void RunTest(ITest test)
        {
            // TODO use an ITestSuiteBuilder, IFixtureBuilder and ITestBuilder instead of a builder factory
            // this would allow more granular builder definitions.
            test.Result.Status = TestStatus.Pass;
            TestTimer timer = new TestTimer();

            List <object[]> parameters = new List <object[]>();

            TestParametersAttribute[] tpas = test.TestMethod.GetCustomAttributes(
                typeof(TestParametersAttribute), false) as TestParametersAttribute[];
            if (tpas != null)
            {
                for (int i = 0; i < tpas.Length; i++)
                {
                    parameters.AddRange(tpas[i].GetParameters(test));
                }
            }

            timer.Start(test);
            for (int i = 0; i < parameters.Count; i++)
            {
                try
                {
                    test.TestMethod.Invoke(test.Fixture.Instance, parameters[i]);
                }
                catch (TargetInvocationException tie)
                {
                    Exception exp = tie.InnerException;
                    test.Result.Status = TestStatus.Fail;
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("Test run {0} failed with parameters: ", i + 1);
                    if (parameters[i] != null && parameters[i].Length > 0)
                    {
                        sb.Append(AssertionFailureMessage.FormatObjectForDisplay(parameters[i][0]));
                        for (int j = 1; j < parameters[i].Length; j++)
                        {
                            sb.AppendFormat(", {0}", AssertionFailureMessage.FormatObjectForDisplay(parameters[i][j]));
                        }
                    }
                    test.Result.Message.AppendLine(sb.ToString());
                    test.Result.Message.AppendLine(exp.Message);
                    test.Result.Message.Append("EXCEPTION TYPE: ");
                    test.Result.Message.AppendLine(exp.GetType().FullName);
                    if (test.Result.StackTrace == null)
                    {
                        test.Result.SetFilteredStackTrace(exp.StackTrace);
                    }
                }
            }
            timer.Stop();
        }
Пример #14
0
        /// <summary>
        /// Executes the inner test method, gathering the amount of time it takes to run.
        /// </summary>
        /// <returns>Returns information about the test run</returns>
        public override MethodResult Execute(object testClass)
        {
            TestTimer timer = new TestTimer();

            timer.Start();
            MethodResult methodResult = InnerCommand.Execute(testClass);

            timer.Stop();

            methodResult.ExecutionTime = timer.ElapsedMilliseconds / 1000.00;

            return(methodResult);
        }
        /// <summary>
        /// Runn the test.
        /// </summary>
        public void RunTest(ITest test)
        {
            TestTimer timer = new TestTimer();

            try
            {
                timer.Start(test);
                test.TestMethod.Invoke(test.Fixture.Instance, null);
                timer.Stop();
            }
            catch (TargetInvocationException tie)
            {
                timer.Stop();
                Type thrownExceptionType = tie.InnerException.GetType();
                test.Result.Message.AppendFormat("Expected Exception: {0}", ExceptionType.FullName);
                if (thrownExceptionType.Equals(ExceptionType) && (Message == null || tie.InnerException.Message == Message))
                {
                    test.Result.Status = TestStatus.Pass;
                    test.Result.Message.AppendLine(" was thrown.");
                }
                else
                {
                    test.Result.Status = TestStatus.Fail;
                    test.Result.Message.AppendLine(" was NOT thrown.");
                }
                test.Result.Message.Append("Message: ");
                test.Result.Message.AppendLine(tie.InnerException.Message);
                test.Result.Message.Append("Exception Type: ");
                test.Result.Message.AppendLine(thrownExceptionType.FullName);
                test.Result.SetFilteredStackTrace(tie.InnerException.StackTrace);
            }
            finally
            {
                timer.Stop();
                if (test.Result.Status == TestStatus.Untested)
                {
                    // No exception has been thrown.

                    test.Result.Status = TestStatus.Fail;
                    test.Result.Message.AppendFormat("Expected Exception: {0}", ExceptionType.FullName);
                    test.Result.Message.AppendLine(" was NOT thrown.");
                    SequenceManager sm = new SequenceManager(test.TestMethod);
                    if (sm.IsSourceAvailable())
                    {
                        test.Result.StackTrace = sm.GetStackTrace(0);
                    }
                }
            }
        }
Пример #16
0
 private void btnCommaxTest_Click(object sender, EventArgs e)
 {
     if (TestTimer.Enabled)
     {
         TestTimer.Stop();
         btnCommaxTest.Text = "시작";
     }
     else
     {
         int sec = 30; //30초;
         int.TryParse(txtCommaxSec.Text, out sec);
         TestTimer.Interval = sec * 1000;
         TestTimer.Start();
         btnCommaxTest.Text = "정지";
     }
 }
Пример #17
0
        public void NextElementIteration()
        {
            isAnswering = !isAnswering;

            timer.Stop();
            if (!isAnswering)
            {
                label.Text = MemoryTest.GetRow();
                timer.Start();
            }

            if (isAnswering)
            {
                textBox.Text = "";
            }

            textBox.Visible = isAnswering;
            label.Visible   = !isAnswering;
            timer.Visible   = !isAnswering;
        }
Пример #18
0
        private void buttonStartDaemon_Click(object sender, EventArgs e)
        {
            try
            {
                if (TestTimer.Enabled)
                {
                    TestTimer.Stop();
                }

                TestTimer.Tick -= Timer_Tick;
            }
            catch
            {
                // ignored
            }

            TestTimerInterval  = Convert.ToInt32(numericUpDownInterval.Value);
            TestTimer.Interval = TestTimerInterval * 60 * 1000;
            TestTimer.Tick    += Timer_Tick;
            TestTimer.Start();
            buttonRunTest_Click(sender, e);
            ChangeControlStatus(buttonStartDaemon, false);
        }
Пример #19
0
        /// <summary>
        /// Run the test.
        /// </summary>
        public void RunTest(ITest test)
        {
            Type       fixtureType = test.Fixture.Instance.GetType();
            MethodInfo method      = test.TestMethod;

            DynamicMethod testMethod = GetTestMethod(fixtureType, method);

            TestTimer timer = new TestTimer();
            Dictionary <int, Exception> exceptionsThrown;
            TestDelegate testDelegate = testMethod.CreateDelegate(typeof(TestDelegate), test.Fixture.Instance) as TestDelegate;

            try
            {
                timer.Start(test);
                exceptionsThrown = testDelegate();
                timer.Stop();
            }
            catch (InvalidProgramException exp)
            {
                timer.Stop();
                throw new InvalidOperationException("Unable to catch thrown exceptions in test method.", exp);
            }
            finally
            {
                timer.Stop();
            }

            SequenceManager sm = new SequenceManager(test.TestMethod);
            int             expectedExceptionCount  = 0;
            int             unexpectedExpectedCount = 0;
            int             i = 0;

            foreach (KeyValuePair <int, Exception> exception in exceptionsThrown)
            {
                if (exception.Value != null)
                {
                    Type thrownExceptionType = exception.Value.GetType();
                    test.Result.Output.AppendFormat("[{0}] Expected Exception: {1}", i + 1, ExceptionType.FullName);
                    if (thrownExceptionType.Equals(ExceptionType))
                    {
                        expectedExceptionCount++;
                        test.Result.Output.AppendLine(" was thrown.");
                    }
                    else
                    {
                        // Get line offset from il instruction offset.
                        unexpectedExpectedCount++;
                        test.Result.Output.AppendLine(" was NOT thrown.");
                        test.Result.Output.Append("\tThrown Exception Was: ");
                        if (sm.IsSourceAvailable())
                        {
                            int    sequenceOffset = Math.Abs(Array.BinarySearch <int>(sm.Offsets, exception.Key));
                            string dynamicLine    = String.Format("   at {0}_TestMethod({1} )",
                                                                  test.TestMethod.Name, test.Fixture.FixtureType.Name);
                            string sourceLine = sm.GetStackTrace(sequenceOffset);
                            test.Result.Output.AppendLine(
                                exception.Value.ToString().Replace(dynamicLine, sourceLine));
                            if (test.Result.StackTrace == null)
                            {
                                test.Result.SetFilteredStackTrace(
                                    exception.Value.StackTrace.Replace(dynamicLine, sourceLine));
                            }
                        }
                        else
                        {
                            test.Result.Output.AppendLine(exception.Value.ToString());
                            if (test.Result.StackTrace == null)
                            {
                                test.Result.SetFilteredStackTrace(exception.Value.StackTrace);
                            }
                        }
                    }
                }
                else
                {
                    test.Result.Output.AppendFormat("[{0}] No exception was thrown.\n", i + 1);
                }
                i++;
            }

            if (test.Result.StackTrace == null && sm.IsSourceAvailable())
            {
                test.Result.StackTrace = sm.GetStackTrace(0);
            }

            int expectedNumberOfExceptions = (ExceptionCount == UseTestCount ? exceptionsThrown.Count : ExceptionCount);

            test.Result.Message.AppendFormat(ExpectedExceptionCountMessage,
                                             ExceptionType.FullName, expectedExceptionCount, exceptionsThrown.Count, expectedNumberOfExceptions,
                                             unexpectedExpectedCount, (unexpectedExpectedCount != 1 ? " was" : "s were"));
            if (expectedExceptionCount != expectedNumberOfExceptions || (FailOnOtherExceptions && unexpectedExpectedCount > 0))
            {
                test.Result.Status = TestStatus.Fail;
            }
            else
            {
                test.Result.Status = TestStatus.Pass;
            }
        }
 private void LoadComplete(Object sender, AsyncCompletedEventArgs e) => timer.Start();