Пример #1
0
        public void GetCompilerTest()
        {
            var target = new Compilers("Directory");

            Assert.AreEqual(target.Count, 0);
            var newCompiler = new Compiler();

            newCompiler.Name = "CPP";
            target.AddCompiler(newCompiler);
            var result = target.GetCompiler("CPP");

            Assert.AreNotEqual(result, null);
            Assert.AreEqual("CPP", result.Name);

            result = target.GetCompiler("BadName");
            Assert.AreEqual(result, null);
        }
Пример #2
0
        public void AddDuplicateCompilerTest()
        {
            var firstCompilers = new Compilers("Compilers");

            firstCompilers.Load();
            firstCompilers.AddCompiler(firstCompilers.GetCompiler("CPP8"));
            //compilers must be unique. same compiler can not be added.
            Assert.AreEqual(firstCompilers.Count, 4);
        }
Пример #3
0
        public void AddDuplicateCompilerTest()
        {
            //creating Compilers from compilers folder
            var firstCompilers = new Compilers("Compilers");

            //initialization
            firstCompilers.Load();
            //trying to add compiler of CPP8 which actually is in Compilers right now !
            firstCompilers.AddCompiler(firstCompilers.GetCompiler("CPP8"));
            //compilers must be unique. same compiler can not be added, thats why test fails yet.
            Assert.AreEqual(firstCompilers.Count, 4);
        }
Пример #4
0
        public string Compile(string source, string language, string[] input, string[] output, int timelimit, int memorylimit)
        {
            // remove after testing
            const string CompilerDirectory = "Compilers";
            var          compilers         = new Compilers(CompilerDirectory);

            compilers.Load();
            //----

            if (string.IsNullOrEmpty(language))
            {
                throw new Exception("Bad language name");
            }

            source = HttpUtility.UrlDecode(source);
            Compiler currentCompiler = compilers.GetCompiler(language);

            if (currentCompiler == null)
            {
                throw new Exception("Can't find compiler with such name");
            }

            string compileFilePath = Classes.Helper.CreateFileForCompilation(source, currentCompiler.Extension);

            var compileTask = new CompileTask(currentCompiler, compileFilePath);

            if (!compileTask.Execute())
            {
                return("CompilationError");
            }

            var executeFilePath = Path.ChangeExtension(compileFilePath, currentCompiler.CompiledExtension);

            for (int i = 0; i < input.Length; i++)
            {
                var currentStatus = Tester.Test(executeFilePath, input[i], output[i], timelimit, memorylimit);

                if (currentStatus.TestResult != "Accepted")
                {
                    currentStatus.TestResult = currentStatus.TestResult + " Test: " + i;
                    return(currentStatus.TestResult);
                }
            }

            return("Accepted");
        }