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"; }
public void LoadTest() { Compilers compilers; // empty compiler folder try { compilers = new Compilers("EmptyCompiler"); compilers.Load(); Assert.AreEqual(compilers.Count, 0); } catch (Exception) { Assert.AreEqual(true, false); } // compiler folder with bad information try { compilers = new Compilers("BadCompilers"); compilers.Load(); Assert.AreEqual(true, false); } catch (Exception) { Assert.AreEqual(true, true); } // compiler folder with correct information try { compilers = new Compilers("Compilers"); compilers.Load(); Assert.AreEqual(compilers.Count, 5); } catch (Exception) { Assert.AreEqual(true, false); } }
public void LoadTest() { var compilers = new Compilers("EmptyCompiler"); compilers.Load(); Assert.AreEqual(compilers.Count, 0); compilers = new Compilers("Compilers"); compilers.Load(); Assert.AreEqual(compilers.Count, 4); }
public void AddInvalidCompilerTest() { //create compilers with bad path var compilers = new Compilers("NoFolderCompilers"); //try to initialize them compilers.Load(); //there is no Assert, because in this test we are expecting an exception. }
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); }
public void AddInvalidCompilerTest() { //create compilers with bad path var compilers = new Compilers("NoFolderCompilers"); //try to initialize them compilers.Load(); }
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); }
protected void Application_Start(object sender, EventArgs e) { compilers = new Compilers(CompilerDirectory); compilers.Load(); }