Esempio n. 1
0
		public static RunningResults Run(RunnerSubmition submission)
		{
			try
			{
				return new SandboxRunner(submission).Run();
			}
			catch (Exception ex)
			{
				return new RunningResults
				{
					Id = submission.Id,
					Verdict = Verdict.SandboxError,
					Error = ex.ToString()
				};
			}
		}
Esempio n. 2
0
		private static RunningResults GetDetails(string code, string input)
		{
			var model = new RunnerSubmition
			{
				Id = Guid.NewGuid().ToString(),
				Code = code,
				Input = input,
				NeedRun = true
			};

			var result = new SandboxRunner(model).Run();
			Assert.IsNotNull(result);
			return result;
		}
Esempio n. 3
0
		public SandboxRunner(RunnerSubmition submission)
		{
			_submission = submission;
			_result.Id = submission.Id;
		}
Esempio n. 4
0
		private static RunSolutionResult GetRunResult(ExerciseBlock exercise, string code)
		{
			var buildResult = exercise.Solution.BuildSolution(code);
			if (buildResult.HasErrors)
				return new RunSolutionResult { IsCompileError = true, CompilationError = buildResult.ErrorMessage, ExecutionServiceName = "uLearn" };
			if (buildResult.HasStyleIssues)
				return new RunSolutionResult { IsStyleViolation = true, CompilationError = buildResult.StyleMessage, ExecutionServiceName = "uLearn" };
			var solution = buildResult.SourceCode;
			var submission = new RunnerSubmition
			{
				Code = solution,
				Id = Utils.NewNormalizedGuid(),
				Input = "",
				NeedRun = true
			};
			var result = SandboxRunner.Run(submission);
			return new RunSolutionResult
			{
				IsRightAnswer = result.Verdict == Verdict.Ok && result.GetOutput().NormalizeEoln() == exercise.ExpectedOutput.NormalizeEoln(),
				ActualOutput = result.GetOutput().NormalizeEoln(),
				CompilationError = result.CompilationOutput,
				ExecutionServiceName = "this",
				IsCompileError = result.Verdict == Verdict.CompilationError,
				ExpectedOutput = exercise.ExpectedOutput.NormalizeEoln()
			};
		}
Esempio n. 5
0
		public void EthalonSolutions_for_Exercises(ExerciseSlide slide)
		{
			var solution = slide.Exercise.Solution.BuildSolution(slide.Exercise.EthalonSolution);
			if (solution.HasErrors)
				FailOnError(slide, solution);
			else
			{
				var submission = new RunnerSubmition()
				{
					Code = solution.SourceCode,
					Id = slide.Id,
					Input = "",
					NeedRun = true
				};
				var result = SandboxRunner.Run(submission);
				var output = result.GetOutput().NormalizeEoln();
				var isRightAnswer = output.NormalizeEoln().Equals(slide.Exercise.ExpectedOutput.NormalizeEoln());
				if (!isRightAnswer)
				{
					Assert.Fail("mistake in: " + slide.Info.UnitName + " - " + slide.Title + "\n" +
								"\tActualOutput: " + output + "\n" +
								"\tExpectedOutput: " + slide.Exercise.ExpectedOutput.NormalizeEoln() + "\n" +
								"\tCompilationError: " + result.CompilationOutput + "\n" +
								"\tSourceCode: " + solution.SourceCode + "\n\n");
				}
			}
		}