Ejemplo n.º 1
0
        // factory construct method
        public static ExerciseProblem GetExerciseProblem(string FilePath)
        {
            // input from file
            string[] Texts = null;
            try
            {
                Texts = System.IO.File.ReadAllLines(FilePath);
            }
            catch (System.Exception FileException)
            {
                System.Console.WriteLine(FileException.Message);
                return(null);
            }

            if (null == Texts || Texts.Length <= 0)
            {
                return(null);
            }

            // locate data
            int NameIndex        = ReadTextProblem.GetIdentifierIndex(Texts, NameIdentifier);
            int DescriptionIndex = ReadTextProblem.GetIdentifierIndex(Texts, DescriptionIdentifier);
            int CountsIndex      = ReadTextProblem.GetIdentifierIndex(Texts, CountsIdentifier);
            int InputIndex       = ReadTextProblem.GetIdentifierIndex(Texts, InputIdentifier);
            int OutputIndex      = ReadTextProblem.GetIdentifierIndex(Texts, OutputIdentifier);

            if (NameIndex == -1 ||
                DescriptionIndex == -1 ||
                CountsIndex == -1 ||
                InputIndex == -1 ||
                OutputIndex == -1)
            {
                return(null);
            }

            // read input from postitions
            string        Name        = ReadTextProblem.ReadText(Texts, NameIndex, DescriptionIndex - 1);
            string        Description = ReadTextProblem.ReadText(Texts, DescriptionIndex, CountsIndex - 1);
            int           Counts      = ReadTextProblem.ReadCounts(Texts, CountsIndex);
            List <string> TestInputs  = ReadTextProblem.ReadTestData(Texts, InputIndex, InputIndex + Counts);
            List <string> TestOutputs = ReadTextProblem.ReadTestData(Texts, OutputIndex, OutputIndex + Counts);

            if (TestInputs == null ||
                TestOutputs == null ||
                Counts < 1)
            {
                return(null);
            }

            // build an ExerciseProblem
            ExerciseProblem problem = new ExerciseProblem(Name, Description, TestInputs, TestOutputs);

            return(problem);
        }
Ejemplo n.º 2
0
        // constructors

        // constructor: construct with a ExerciseProblem
        public ExerciseSingle(ExerciseProblem problem) :
            base(problem.Name)
        {
            this.Problem = (ExerciseProblem)problem.Clone();
        }