示例#1
0
        private void ValidateOutput()
        {
            if (Output == null || Output.Count() == 0)
            {
                FailReason    = "Ausgabe des Programms ist leer.";
                OutputMatches = false;
                return;
            }

            var cleanedOutput         = Output.Where(x => string.IsNullOrWhiteSpace(x) == false);
            var cleanedExpectedOutput = ExpectedOutput.Where(x => string.IsNullOrWhiteSpace(x) == false);
            int lineDifference        = cleanedExpectedOutput.Count() - cleanedOutput.Count();

            if (lineDifference != 0)
            {
                string linePlural = (Math.Abs(lineDifference) == 1 ? "" : "n");
                string difference = (lineDifference > 0 ? "wenig" : "viel");
                FailReason    = $"Die Ausgabe hat {Math.Abs(lineDifference)} Zeile{linePlural} zu {difference}.";
                OutputMatches = false;
                return;
            }

            for (int i = 0; i < cleanedExpectedOutput.Count(); ++i)
            {
                if (string.Equals(cleanedOutput.ElementAt(i), cleanedExpectedOutput.ElementAt(i)) == false)
                {
                    FailReason    = $"Zeile {i + 1} ist nicht identisch.";
                    OutputMatches = false;
                    return;
                }
            }

            OutputMatches = true;
        }
示例#2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (ExerciseInitialCode != null ? ExerciseInitialCode.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ExpectedOutput != null ? ExpectedOutput.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (HintsMd != null ? HintsMd.GetHashCode() : 0);
         return(hashCode);
     }
 }
示例#3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ExerciseInitialCode?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (ExpectedOutput?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (HintsMd?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
        public Boolean Run()
        {
            // run lexer on input
            var lexer       = new SGLLexer(new ANTLRStringStream(Input));
            var tokenStream = new CommonTokenStream(lexer);

            // run parser on tokens
            var parser = new SGLParser(tokenStream);
            var ast    = (CommonTree)parser.main().Tree;

            // maybe test the tree
            if (testTree)
            {
                if (!ast.ToStringTree().Trim().Equals(ExpectedTree.Trim()))
                {
                    result += "Test " + name + "failed! Tree comparison failed!";
                    result += "Expected tree: " + ExpectedTree.Trim();
                    result += "Given tree: " + ast.ToStringTree().Trim();
                    return(false);
                }
            }

            var astStream = new CommonTreeNodeStream(ast);

            // run walker on AST
            GlobalMemory.Clear();
            var treewalker = new SGLTreeWalker(astStream, true);

            treewalker.main().Evaluate();
            //String output = treewalker.GetStoryboardCode().ToString();
            if (testOutput)
            {
                String output = GlobalMemory.Instance.StoryboardCode.ToString();
                if (!output.Trim().Equals(ExpectedOutput.Trim()))
                {
                    result += "Test " + name + "failed! Output comparison failed!";
                    result += "Expected output: \r\n" + ExpectedOutput.Trim();
                    result += "Given output: \r\n" + output.Trim();
                    return(false);
                }
            }

            if (testDebug)
            {
                String debug = GlobalMemory.Instance.StoryboardCode.ToString();
                if (!debug.Trim().Equals(ExpectedDebug.Trim()))
                {
                    result += "Test " + name + "failed! Debug comparison failed!";
                    result += "Expected debug: \r\n" + ExpectedDebug.Trim();
                    result += "Given debug: \r\n" + debug.Trim();
                    return(false);
                }
            }
            return(true);
        }
示例#5
0
        public void Format()
        {
            FormattingContext context     = FormattingContext.PageContent;
            PageInfo          currentPage = null;

            string[] linkedPages = null;

            string output = Formatter.Format(Input, false, context, currentPage, out linkedPages, false);

            // Ignore \r characters
            Assert.AreEqual(ExpectedOutput.Replace("\r", ""), output.Replace("\r", ""), "Formatter output is different from expected output");
        }
        private void AssertSuccessByExecutionForSingleTest()
        {
            Assert.IsNotNull(BodyCodeBlock);

            methodEmitter.ParseTree(BodyCodeBlock);
            methodEmitter.SetAsEntryPoint();
            Assert.IsTrue(assemblyEmitter.Save());

            PEVerifyRunner.Run(assemblyEmitter.OutputPath);
            var stdout = ManagedCodeRunner.CreateProcessAndRun(assemblyEmitter.OutputPath, new string[0] {
            });

            Assert.AreEqual(ExpectedOutput.Trim(), stdout.Trim());
        }
        private bool IsSuccess()
        {
            bool IsSuccessStatus()
            {
                return(Status == CodeRunStatus.Success);
            }

            bool IsSameOutput()
            {
                return(string.Equals(UserOutput.Trim(), ExpectedOutput.Trim(), StringComparison.InvariantCulture));
            }

            return(IsSuccessStatus() && IsSameOutput());
        }
示例#8
0
        //################################################################################
        #region Private Members

        private void Initialize()
        {
            //Read input file to input data list
            using (var stream = new StreamReader(Path.Combine(m_FolderPath, m_InputFileName)))
            {
                while (!stream.EndOfStream)
                {
                    m_InputData.Add(stream.ReadLine());
                }
            }

            //Read output file to output data list
            using (var stream = new StreamReader(Path.Combine(m_FolderPath, m_OutputFileName)))
            {
                while (!stream.EndOfStream)
                {
                    ExpectedOutput.Add(stream.ReadLine());
                }
            }
        }
示例#9
0
 public override string ToString()
 {
     return($"{TestCaseName} -> {string.Join(", ", Params)} \n {ExpectedOutput.ToJson()}");
 }
示例#10
0
        public void InsertNumber()
        {
            //initial input
            string input = "6000";
            //expected output
            const bool ExpectedOutput = true;
            //max retrieved inputs
            int maxInputs = 5;

            //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++)
            {
                //creating the condition for the testcase
                clsCondition condition1 = new clsCondition(clsEnums.Condition.IS_NUMERIC, Inputs[i], ExpectedOutput.ToString(), ActualOutput.AnalyzeNumber(Inputs[i], clsEnums.Condition.IS_NUMERIC));
                TestOracle.AppendConditions(condition1);
                //validating the condition
                TestOracle.ValidateTestConditions("Should be a number");
            }
            //printing the results
            TestOracle.PrintResults();
        }