Example #1
0
 public TestSet(object prototypeObject, string description, Action speedFactorMeasureFunction = null, object settings = null, int stackSize = 1)
 {
     _prototypeObject            = prototypeObject;
     Description                 = description;
     SpeedFactor                 = TimeLimitRunner.CalculateSpeedFactor(speedFactorMeasureFunction);
     _speedFactorMeasureFunction = speedFactorMeasureFunction;
     _settings  = settings;
     _stackSize = stackSize;
 }
Example #2
0
        private string PerformSingleTest(TestCase testCase, object proxyPrototypeObject, bool checkTimeLimit, bool verbose)
        {
            testCase.PerformanceTime = TimeLimitRunner.Run(SpeedFactor * testCase.TimeLimit, checkTimeLimit, testCase.ExpectedException, out var timeout, out var thrownException,
                                                           () => testCase.PerformTestCase(proxyPrototypeObject), _stackSize) / SpeedFactor;
            testCase.Timeout         = timeout;
            testCase.ThrownException = thrownException;
            string result;

            if (testCase.ThrownException != null)
            {
                if (testCase.ExpectedException == null)
                {
                    testCase.ResultCode = TestCase.Result.UnexpectedExceptionThrown;
                    testCase.Message    = testCase.ThrownException.Message;
                    FailedCount++;
                    result = "unexpected exception";
                }
                else if (testCase.ThrownException.GetType() != testCase.ExpectedException.GetType())
                {
                    testCase.ResultCode = TestCase.Result.IncorrectExceptionThrown;
                    testCase.Message    = testCase.ThrownException.Message;
                    FailedCount++;
                    result = "incorrect exception";
                }
                else
                {
                    testCase.ResultCode = TestCase.Result.ExpectedExceptionThrown;
                    testCase.Message    = $"OK, expected exception of type {testCase.ThrownException.GetType()} thrown";
                    PassedCount++;
                    result = "OK, expected exception thrown";
                }
            }
            else if (testCase.ExpectedException != null)
            {
                testCase.ResultCode = TestCase.Result.ExceptionNotThrown;
                testCase.Message    = $"error, expected exception of type {testCase.ExpectedException.GetType()} not thrown";
                FailedCount++;
                result = "error, expected exception not thrown";
            }
            else if (testCase.Timeout)
            {
                testCase.ResultCode = TestCase.Result.Timeout;
                testCase.Message    = $"computation interrupted (time limit {testCase.TimeLimit} time units exceeded)";
                TimeoutsCount++;
                FailedCount++;
                result = "timeout";
            }
            else
            {
                (testCase.ResultCode, testCase.Message) = testCase.VerifyTestCase(_settings);
                if (testCase.ResultCode < TestCase.Result.WrongResult && testCase.ResultCode != TestCase.Result.Success && testCase.ResultCode != TestCase.Result.LowEfficiency)
                {
                    throw new Exception("Test engine error: invalid result code");
                }
                if (testCase.Message == null || testCase.Message.Trim() == string.Empty)
                {
                    throw new Exception("Test engine error: invalid result message");
                }
                if (testCase.ResultCode != TestCase.Result.Success)
                {
                    if (testCase.ResultCode != TestCase.Result.LowEfficiency)
                    {
                        if (testCase.ResultCode != TestCase.Result.WrongResult)
                        {
                            FailedCount++;
                            result = "undescribed error";
                        }
                        else
                        {
                            FailedCount++;
                            result = "wrong result";
                        }
                    }
                    else
                    {
                        LowEfficiencyCount++;
                        PassedCount++;
                        result = "low efficiency";
                    }
                }
                else
                {
                    PassedCount++;
                    result = "OK";
                }
            }
            return(!verbose ? result : testCase.Message);
        }
Example #3
0
 private void OnDeserializedCalculateSpeedFactor(StreamingContext context)
 {
     SpeedFactor = TimeLimitRunner.CalculateSpeedFactor(_speedFactorMeasureFunction);
 }