示例#1
0
        public void SayHelloWorld2()
        {
            //initial input
            string input = "hello world";
            //expected output
            const string ExpectedOutput = "hello world";
            //setting max inputs
            int maxInputs = 5;

            //classifying initial input and retrieving auxiliary inputs
            string[] Inputs = InputHelper.RetrieveInputs(input, maxInputs);

            for (int i = 0; i < Inputs.Length; i++)
            {
                //getting actual outputs
                bool ActualOutputFirstCondition  = ActualOutput.CompareString(Inputs[i], ExpectedOutput);
                bool ActualOutputSecondCondition = ActualOutput.CompareStringLength(Inputs[i].Length, ExpectedOutput.Length, clsEnums.Operand.EQUAL);
                //setting conditions
                clsCondition condition1 = new clsCondition(clsEnums.Condition.STRINGS_MATCH, Inputs[i], ExpectedOutput, ActualOutputFirstCondition);
                clsCondition condition2 = new clsCondition(clsEnums.Condition.STRING_LENGTH_EQUAL, Inputs[i].Length, ExpectedOutput.Length, ActualOutputSecondCondition);
                //appending conditions
                TestOracle.AppendConditions(condition1);
                TestOracle.AppendConditions(condition2);
                //validating conditions
                TestOracle.ValidateTestConditions("Should print hello world");
            }
            //printing tests
            TestOracle.PrintResults();
        }
示例#2
0
        public void SayHelloWorld()
        {
            //initial input
            string input = "hello wrld";
            //expected output
            const string ExpectedOutput = "hello world";

            //Getting the actual outputs...
            bool ActualOutputFirstCondition  = ActualOutput.CompareString(input, ExpectedOutput);
            bool ActualOutputSecondCondition = ActualOutput.CompareStringLength(input.Length, ExpectedOutput.Length, clsEnums.Operand.EQUAL);

            //conditon 1 input and expected output should match
            clsCondition condition1 = new clsCondition(clsEnums.Condition.STRINGS_MATCH, input, ExpectedOutput, ActualOutputFirstCondition);
            //conditon 2 input and expected put must have the same length
            clsCondition condition2 = new clsCondition(clsEnums.Condition.STRING_LENGTH_EQUAL, input.Length, ExpectedOutput.Length, ActualOutputSecondCondition);

            //appending conditions
            TestOracle.AppendConditions(condition1);
            TestOracle.AppendConditions(condition2);

            //validating the results
            TestOracle.ValidateTestConditions("Should print hello world but has an typo");
            //printing results
            TestOracle.PrintResults();
        }
示例#3
0
        public void InsertNumber2()
        {
            ////initial input
            string input = "HelloWorld";
            //expected output
            const bool ExpectedOutput = true;
            //max retrieved inputs
            int maxInputs = 2;

            //classifying and retrieving all the inputs
            string[] Inputs = InputHelper.RetrieveInputs(input, maxInputs);

            //for every input generate an additional testcase
            for (int i = 0; i < Inputs.Length; i++)
            {
                //getting actual output
                bool ActualOutputFirstCondition = ActualOutput.AnalyzeNumber(Inputs[i], clsEnums.Condition.IS_NUMERIC);
                //creating the condition for the testcase
                clsCondition condition1 = new clsCondition(clsEnums.Condition.IS_NUMERIC, Inputs[i], ExpectedOutput.ToString(), ActualOutputFirstCondition);
                TestOracle.AppendConditions(condition1);
                //validating the condition
                TestOracle.ValidateTestConditions("Should be a number but is a string");
            }
            TestOracle.PrintResults();
        }
示例#4
0
        public void SayHelloWorld2()
        {
            //initial input
            string input = "Not Hello World";
            //expected output
            const string ExpectedOutput = "Hello world";
            //setting max inputs
            int maxInputs = 5;

            //classifying initial input and retrieving auxiliary inputs
            string[] Inputs = InputHelper.RetrieveInputs(input, maxInputs);

            for (int i = 0; i < Inputs.Length; i++)
            {
                //getting actual outputs
                bool ActualOutputFirstCondition  = ActualOutput.CompareString(Inputs[i], ExpectedOutput);
                bool ActualOutputSecondCondition = ActualOutput.CompareStringLength(Inputs[i].Length, ExpectedOutput.Length, clsEnums.Operand.EQUAL);
                //setting condition the input must match the expected output
                clsCondition condition1 = new clsCondition
                                          (
                    clsEnums.Condition.STRINGS_MATCH, //input and expected output must match
                    Inputs[i],                        //next input
                    ExpectedOutput,                   //the expected output
                    ActualOutputFirstCondition        //the actual output
                                          );
                //setting up the condition that the input and expected output must have the same length
                clsCondition condition2 = new clsCondition
                                          (
                    clsEnums.Condition.STRING_LENGTH_EQUAL, //input and expected output length must be equal
                    Inputs[i].Length,                       //next input
                    ExpectedOutput.Length,                  //the expected output
                    ActualOutputSecondCondition             //the actual output
                                          );
                //appending conditions
                TestOracle.AppendConditions(condition1);
                TestOracle.AppendConditions(condition2);
                //validating conditions
                TestOracle.ValidateTestConditions("Input Must Be Hello World");
            }
            //printing tests
            TestOracle.PrintResults();
        }
示例#5
0
        public override void When()
        {
#pragma warning disable IDE0019 // Use pattern matching
            var stringValue = Input as string;
            var stringArray = Input as IEnumerable <string>;
#pragma warning restore IDE0019 // Use pattern matching

            if (stringValue != null)
            {
                ActualOutput = (T)Instance.Map(stringValue);
            }
            else if (stringArray != null)
            {
                ActualOutput = (T)Instance.Map(stringArray).Values;
            }
            else
            {
                ActualOutput = Input;
            }

            Debug.Print("Result: " + ActualOutput.ToUsefulString());
        }
示例#6
0
 public void the_actual_output_is_the_expected_output()
 {
     ActualOutput.ShouldEqual(ExpectedOutput);
 }
示例#7
0
 public override void When()
 {
     ActualOutput = Instance.Map(Input).Values.Select(s => s.ToString());
     Debug.Print("Result: " + ActualOutput.ToUsefulString());
 }
示例#8
0
        private void Evaluate()
        {
            Pass = true;
            if (_hasErrors && Case.ExpectedOutputs.Any(r => r.Exception) != true)
            {
                Pass = false;
            }
            foreach (var caseExpectedOutput in Case.ExpectedOutputs)
            {
                var matchingValue  = caseExpectedOutput.ValueToMatch;
                var testResultFail = false;

                if (caseExpectedOutput.Exception)
                {
                    var msg = _exception?.Message;
                    testResultFail = CaseSensitivity(caseExpectedOutput, msg, matchingValue);
                }
                else if (caseExpectedOutput.MatchOutputIndex == null)
                {
                    testResultFail = ActualOutput.All(p => CaseSensitivity(caseExpectedOutput, p, matchingValue));
                }
                else if (caseExpectedOutput.MatchOutputIndex is int i)
                {
                    var output = ActualOutput.ToList();
                    if (i < output.Count)
                    {
                        testResultFail = CaseSensitivity(caseExpectedOutput, output[i], matchingValue);
                    }
                    else
                    {
                        testResultFail = true;
                        ErrorMessage  += $"Case {Case.CaseNumber}: 'Expected {i+1} outputs but there was only {output.Count} outputs\r\n";
                    }
                }
                if (caseExpectedOutput.Regex)
                {
                    var options = caseExpectedOutput.CaseInsensitive ? RegexOptions.IgnoreCase : RegexOptions.None;
                    testResultFail = ActualOutput.All(p => p != null && Regex.IsMatch(p, caseExpectedOutput.ValueToMatch, options) != true);
                }
                if (caseExpectedOutput.Negate)
                {
                    testResultFail = !testResultFail;
                }

                if (testResultFail)
                {
                    Pass = false;

                    if (string.IsNullOrWhiteSpace(caseExpectedOutput.Hint) != true)
                    {
                        ErrorMessage += $"Case {Case.CaseNumber}: '{caseExpectedOutput.Hint}'\r\n";
                    }
                    var expected = "Expected";
                    if (caseExpectedOutput.Negate)
                    {
                        expected = "Not Expected";
                    }

                    var index = "";
                    if (caseExpectedOutput.MatchOutputIndex is int i)
                    {
                        index = $" at output index {i}";
                    }
                    if (caseExpectedOutput.Exception)
                    {
                        ErrorMessage += $"Case {Case.CaseNumber}: {expected} Exception('{caseExpectedOutput.ValueToMatch}')\r\n";
                    }
                    else
                    {
                        ErrorMessage += $"Case {Case.CaseNumber}: {expected} '{caseExpectedOutput.ValueToMatch}'{index}\r\n";
                    }
                }
                else
                {
                    ErrorMessage = "";
                }
            }
            if (!Pass)
            {
                ErrorMessage += $"Case {Case.CaseNumber}: Failed";
            }
        }