Exemplo n.º 1
0
        public async Task GradeSubmissionAsync_WrongReturnType_Error()
        {
            var question   = GetMethodQuestion();
            var submission = new CodeQuestionSubmission()
            {
                Contents = "Submission"
            };
            var methodJobResult = GetFailedMethodJobResult
                                  (
                new MethodDefinition()
            {
                IsPublic       = true,
                IsStatic       = true,
                Name           = "expectedMethod",
                ParameterTypes = Collections.CreateList("int", "int"),
                ReturnType     = "boolean"
            }
                                  );

            var codeRunnerService = GetCodeRunnerService(methodJobResult);
            var grader            = new MethodQuestionGrader(question, codeRunnerService);
            var result            = await grader.GradeSubmissionAsync(submission);

            var codeQuestionResult    = (CodeQuestionResult)result.Result;
            var methodReturnTypeError = codeQuestionResult.Errors
                                        .Cast <MethodReturnTypeError>()
                                        .Single();

            Assert.Equal(0.0, result.Score);
            Assert.Equal("expectedMethod", methodReturnTypeError.MethodName);
            Assert.Equal("int", methodReturnTypeError.ExpectedReturnType);
            Assert.Equal("boolean", methodReturnTypeError.ActualReturnType);
        }
		public async Task GradeSubmissionAsync_MethodJobHasCorrectCode()
		{
			var question = GetMethodQuestion();
			var methodJobResult = GetSuccessfulMethodJobResult();
			var submission = new CodeQuestionSubmission() { Contents = "Submission %" };
			var codeRunnerService = GetCodeRunnerService
			(
				methodJobResult,
				job => job.MethodCode == "Submission %%"
			);

			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);

			Assert.Equal(1.0, result.Score);
		}
		public async Task GradeSubmissionAsync_MethodJobHasImportedClasses()
		{
			var question = GetMethodQuestion();
			var methodJobResult = GetSuccessfulMethodJobResult();
			var submission = new CodeQuestionSubmission() { Contents = "Submission" };
			var codeRunnerService = GetCodeRunnerService
			(
				methodJobResult,
				job => job.ClassesToImport.Count == 1
					&& job.ClassesToImport[0] == "package.classToImport"
			);

			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);

			Assert.Equal(1.0, result.Score);
		}
		public async Task GradeSubmissionAsync_MethodJobHasTests()
		{
			var question = GetMethodQuestion();
			var methodJobResult = GetSuccessfulMethodJobResult();
			var submission = new CodeQuestionSubmission() { Contents = "Submission %" };
			var codeRunnerService = GetCodeRunnerService
			(
				methodJobResult,
				job => job.Tests.Count == 1
					&& job.Tests[0].TestName == "test1"
					&& job.Tests[0].ParamValues == "1, 2"
			);

			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);

			Assert.Equal(1.0, result.Score);
		}
Exemplo n.º 5
0
        public async Task GradeSubmissionAsync_CorrectSubmission_ValidTestDescription()
        {
            var question   = GetMethodQuestion();
            var submission = new CodeQuestionSubmission()
            {
                Contents = "Submission"
            };
            var methodJobResult   = GetSuccessfulMethodJobResult();
            var codeRunnerService = GetCodeRunnerService(methodJobResult);

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            var codeQuestionResult = (CodeQuestionResult)result.Result;
            var testResult         = codeQuestionResult.TestResults.Single();

            Assert.Equal("expectedMethod(1, 2)", testResult.Description);
        }
Exemplo n.º 6
0
        public async Task GradeSubmissionAsync_MethodJobHasCorrectCode()
        {
            var question        = GetMethodQuestion();
            var methodJobResult = GetSuccessfulMethodJobResult();
            var submission      = new CodeQuestionSubmission()
            {
                Contents = "Submission %"
            };
            var codeRunnerService = GetCodeRunnerService
                                    (
                methodJobResult,
                job => job.MethodCode == "Submission %%"
                                    );

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(1.0, result.Score);
        }
Exemplo n.º 7
0
        public async Task GradeSubmissionAsync_CorrectSubmission_CorrectScore(bool useGenerics)
        {
            var question   = GetMethodQuestion(useGenerics);
            var submission = new CodeQuestionSubmission()
            {
                Contents = "Submission"
            };
            var methodJobResult   = GetSuccessfulMethodJobResult(useGenerics);
            var codeRunnerService = GetCodeRunnerService(methodJobResult);

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            var codeQuestionResult = (CodeQuestionResult)result.Result;
            var testResult         = codeQuestionResult.TestResults.Single();

            Assert.Equal(1.0, result.Score);
            Assert.Empty(codeQuestionResult.Errors);
        }
Exemplo n.º 8
0
        public async Task GradeSubmissionAsync_MethodJobHasImportedClasses()
        {
            var question        = GetMethodQuestion();
            var methodJobResult = GetSuccessfulMethodJobResult();
            var submission      = new CodeQuestionSubmission()
            {
                Contents = "Submission"
            };
            var codeRunnerService = GetCodeRunnerService
                                    (
                methodJobResult,
                job => job.ClassesToImport.Count == 1 &&
                job.ClassesToImport[0] == "package.classToImport"
                                    );

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(1.0, result.Score);
        }
Exemplo n.º 9
0
        public async Task GradeSubmissionAsync_MethodJobHasTests()
        {
            var question        = GetMethodQuestion();
            var methodJobResult = GetSuccessfulMethodJobResult();
            var submission      = new CodeQuestionSubmission()
            {
                Contents = "Submission %"
            };
            var codeRunnerService = GetCodeRunnerService
                                    (
                methodJobResult,
                job => job.Tests.Count == 1 &&
                job.Tests[0].TestName == "test1" &&
                job.Tests[0].ParamValues == "1, 2"
                                    );

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(1.0, result.Score);
        }
Exemplo n.º 10
0
        public async Task GradeSubmissionAsync_MissingMethod_Error()
        {
            var question   = GetMethodQuestion();
            var submission = new CodeQuestionSubmission()
            {
                Contents = "Submission"
            };
            var methodJobResult   = GetFailedMethodJobResult(definition: null);
            var codeRunnerService = GetCodeRunnerService(methodJobResult);

            var grader = new MethodQuestionGrader(question, codeRunnerService);
            var result = await grader.GradeSubmissionAsync(submission);

            var codeQuestionResult = (CodeQuestionResult)result.Result;
            var methodMissingError = codeQuestionResult.Errors
                                     .Cast <MethodMissingError>()
                                     .Single();

            Assert.Equal(0.0, result.Score);
            Assert.Equal("expectedMethod", methodMissingError.ExpectedMethodName);
            Assert.True(methodMissingError.ExpectedStatic);
        }
		public async Task GradeSubmissionAsync_MissingMethod_Error()
		{
			var question = GetMethodQuestion();
			var submission = new CodeQuestionSubmission() { Contents = "Submission" };
			var methodJobResult = GetFailedMethodJobResult(definition: null);
			var codeRunnerService = GetCodeRunnerService(methodJobResult);

			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);
			var codeQuestionResult = (CodeQuestionResult)result.Result;
			var methodMissingError = codeQuestionResult.Errors
				.Cast<MethodMissingError>()
				.Single();

			Assert.Equal(0.0, result.Score);
			Assert.Equal("expectedMethod", methodMissingError.ExpectedMethodName);
			Assert.True(methodMissingError.ExpectedStatic);
		}
		public async Task GradeSubmissionAsync_CorrectSubmission_ValidTestDescription()
		{
			var question = GetMethodQuestion();
			var submission = new CodeQuestionSubmission() { Contents = "Submission" };
			var methodJobResult = GetSuccessfulMethodJobResult();
			var codeRunnerService = GetCodeRunnerService(methodJobResult);

			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);
			var codeQuestionResult = (CodeQuestionResult)result.Result;
			var testResult = codeQuestionResult.TestResults.Single();

			Assert.Equal(1.0, result.Score);
			Assert.Equal(0, codeQuestionResult.Errors.Count);
			Assert.Equal("expectedMethod(1, 2)", testResult.Description);
		}
		public async Task GradeSubmissionAsync_WrongParameterTypes_Error()
		{
			var question = GetMethodQuestion();
			var submission = new CodeQuestionSubmission() { Contents = "Submission" };
			var methodJobResult = GetFailedMethodJobResult
			(
				new MethodDefinition()
				{
					IsPublic = true,
					IsStatic = true,
					Name = "expectedMethod",
					ParameterTypes = Collections.CreateList("int", "double"),
					ReturnType = "int"
				}
			);

			var codeRunnerService = GetCodeRunnerService(methodJobResult);
			var grader = new MethodQuestionGrader(question, codeRunnerService);
			var result = await grader.GradeSubmissionAsync(submission);
			var codeQuestionResult = (CodeQuestionResult)result.Result;
			var methodParameterTypesError = codeQuestionResult.Errors
				.Cast<MethodParameterTypesError>()
				.Single();

			Assert.Equal(0.0, result.Score);
			Assert.Equal("expectedMethod", methodParameterTypesError.MethodName);
			Assert.Equal(2, methodParameterTypesError.ExpectedParamTypes.Count);
			Assert.Equal("int", methodParameterTypesError.ExpectedParamTypes[0]);
			Assert.Equal("int", methodParameterTypesError.ExpectedParamTypes[1]);
			Assert.Equal("int", methodParameterTypesError.ActualParamTypes[0]);
			Assert.Equal("double", methodParameterTypesError.ActualParamTypes[1]);
		}