public void SubmitActionWhenUserIsNotRegisteredToParticipateShouldThrowException() { var contest = this.CreateAndSaveContest("someContest", this.ActiveContestNoPasswordOptions, this.ActiveContestNoPasswordOptions); var problem = new Problem { Name = "test problem" }; var submissionType = new SubmissionType { Name = "test submission type" }; contest.Problems.Add(problem); contest.SubmissionTypes.Add(submissionType); this.EmptyOjsData.SaveChanges(); var submission = new SubmissionModel { Content = "test submission", ProblemId = problem.Id, SubmissionTypeId = submissionType.Id }; try { var result = this.CompeteController.Submit(submission, this.IsCompete); Assert.Fail("An exception was expected when a user is trying to submit for a contest that he isn't registered for."); } catch (HttpException ex) { Assert.AreEqual((int)HttpStatusCode.Unauthorized, ex.GetHttpCode()); } }
public void SubmitActionWhenParticipantSendsAValidSubmitShouldReturnJson() { var contest = this.CreateAndSaveContest("test contest", this.ActiveContestNoPasswordOptions, this.ActiveContestNoPasswordOptions); var problem = new Problem { Name = "test problem" }; var submissionType = new SubmissionType { Name = "test submission type" }; contest.Problems.Add(problem); contest.SubmissionTypes.Add(submissionType); contest.Participants.Add(new Participant(contest.Id, this.FakeUserProfile.Id, this.IsCompete)); this.EmptyOjsData.SaveChanges(); var submission = new SubmissionModel { Content = "test content", ProblemId = problem.Id, SubmissionTypeId = submissionType.Id }; var result = this.CompeteController.Submit(submission, this.IsCompete) as JsonResult; var receivedContestId = (int)result.Data; Assert.AreEqual(receivedContestId, contest.Id); }
public void ContestsBySubmissionType_MultipleSubmissionsWithDifferentTypes_ShouldReturnPartialContests() { Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); for (int i = 0; i < 10; i++) { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 100000); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); int contestId = this.idGen.Next(0, 100000); int points = this.idGen.Next(0, 100000); Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); } this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); } IEnumerable <int> result = this.judge.ContestsBySubmissionType(SubmissionType.CSharpCode); CollectionAssert.AreEqual(submissions.Values.Where(x => x.Type == SubmissionType.CSharpCode).Select(x => x.ContestId), result); }
public void AddSubmission_SingleSubmissionWithValidContestAndUser_ShouldIncreaseCount() { Assert.AreEqual(0, this.judge.GetSubmissions().Count()); int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 100000); int contestId = this.idGen.Next(0, 100000); int points = this.idGen.Next(0, 100000); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); Submission submission = new Submission(submissionId, points, type, contestId, userId); this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); IEnumerable <Submission> result = this.judge.GetSubmissions(); Assert.AreEqual(submissionId, result.First().Id); Assert.AreEqual(type, result.First().Type); Assert.AreEqual(points, result.First().Points); Assert.AreEqual(contestId, result.First().ContestId); Assert.AreEqual(userId, result.First().UserId); Assert.AreEqual(1, this.judge.GetSubmissions().Count()); }
public void SubmissionsInContestIdByUserIdWithPoints_WithInvalidUser_ShouldThrow() { Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); List <int> ids = new List <int>(); for (int i = 0; i < 5; i++) { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 5); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); int contestId = this.idGen.Next(0, 5); int points = this.idGen.Next(0, 5); Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); ids.Add(submissionId); } this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); } int subId = this.idGen.Next(0, ids.Count); Submission sub = submissions[ids[subId]]; Assert.Throws <InvalidOperationException>(() => this.judge.SubmissionsInContestIdByUserIdWithPoints(sub.Points, sub.ContestId, 7)); }
public void GetSubmissionContentWhenInvalidSubmissionIdShouldThrowException() { var contest = this.CreateAndSaveContest("sample Name", this.ActiveContestNoPasswordOptions, this.ActiveContestNoPasswordOptions); var problem = new Problem(); contest.Problems.Add(problem); var submissionType = new SubmissionType(); contest.SubmissionTypes.Add(submissionType); var participant = new Participant(contest.Id, this.FakeUserProfile.Id, this.IsCompete); contest.Participants.Add(participant); var submission = new Submission { ContentAsString = "test content" }; participant.Submissions.Add(submission); this.EmptyOjsData.SaveChanges(); try { var result = this.CompeteController.GetSubmissionContent(-1); Assert.Fail("Expected an exception when an invalid submission id is provided."); } catch (HttpException ex) { Assert.AreEqual((int)HttpStatusCode.NotFound, ex.GetHttpCode()); } }
public void GetSubmissions_MultipleSubmissions_ShouldReturnOrderedCollection() { Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); for (int i = 0; i < 5; i++) { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 100000); int contestId = this.idGen.Next(0, 100000); int points = this.idGen.Next(0, 100000); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); } this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); } IEnumerable <Submission> result = this.judge.GetSubmissions(); CollectionAssert.AreEqual(submissions.Values.OrderBy(x => x.Id), result); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { return(this.byInsertion.Values .Where(s => s.Type == submissionType) .Select(s => s.ContestId) .Distinct()); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { return(byId.Values .Where(x => x.Type == submissionType) .Select(x => x.ContestId) .Distinct()); }
public void GetAllowedSubmissionTypesWhenRequestIsValidShouldReturnSubmissionTypes() { var contest = this.CreateAndSaveContest("testName", this.ActiveContestWithPasswordAndQuestionsOptions, this.ActiveContestWithPasswordAndQuestionsOptions); var javaSubmissionType = new SubmissionType { IsSelectedByDefault = true, Name = "java type", CompilerType = CompilerType.Java }; var csharpSubmissionType = new SubmissionType { Name = "c# type", CompilerType = CompilerType.CSharp }; contest.SubmissionTypes.Add(javaSubmissionType); contest.SubmissionTypes.Add(csharpSubmissionType); this.EmptyOjsData.SaveChanges(); var result = this.CompeteController.GetAllowedSubmissionTypes(contest.Id) as JsonResult; var data = result.Data as IEnumerable <SelectListItem>; Assert.IsNotNull(result); Assert.AreEqual(contest.SubmissionTypes.Count, data.Count()); Assert.IsFalse(data.Any(x => !contest.SubmissionTypes.Any(t => t.Id.ToString() == x.Value && t.Name == x.Text))); Assert.IsTrue(data.FirstOrDefault(x => x.Text == "java type").Selected); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { return(this.submissions .Values .Where(x => x.Type == submissionType) .Select(x => x.ContestId)); }
public void ContestsByPoints_WithExistingSubmissions_ShouldReturnCorrectContests() { Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); for (int i = 0; i < 30000; i++) { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 5); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); int contestId = this.idGen.Next(0, 15); int points = this.idGen.Next(0, 30); Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); } this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); } var expected = submissions.Values.Where(x => x.UserId == 3).GroupBy(x => x.ContestId).Select(x => x.OrderByDescending(s => s.Points).ThenBy(s => s.Id).First()).OrderByDescending(x => x.Points).ThenBy(x => x.Id).Select(x => x.ContestId); var sw = Stopwatch.StartNew(); IEnumerable <int> result = this.judge.ContestsByUserIdOrderedByPointsDescThenBySubmissionId(3); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 200); CollectionAssert.AreEqual(expected, result); }
/// <summary> /// Gets the submission type of a document as an HTML-formatted tooltip-enabled string. /// </summary> /// <param name="document">The <see cref="SubmissionDocument"/> to get a tooltip for.</param> internal string GetSubmissionTypeText(SubmissionDocument document) { SubmissionType type = document.SubmissionType; string cssClass = string.Empty; switch (type) { case SubmissionType.Regular: cssClass = this.RegularTooltipCssClass; break; case SubmissionType.Amendment: cssClass = this.AmendmentTooltipCssClass; break; case SubmissionType.Resubmission: cssClass = this.ResubmissionTooltipCssClass; break; case SubmissionType.InternalAmendment: cssClass = this.IAmendmentTooltipCssClass; break; case SubmissionType.Documentation: cssClass = this.DocumentationTooltipCssClass; break; } return(string.Format("{0} {1}", CPConvert.ToString(type), string.Format(Properties.Settings.Default.TooltipFormat, string.Format("{0} {1}", this.TooltipCssClass, cssClass)))); }
public void GetSubmissions_MultipleSubmissions_ShouldReturnOrderedCollection() { Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 30000; i++) { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 100000); int contestId = this.idGen.Next(0, 100000); int points = this.idGen.Next(0, 100000); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); } this.judge.AddContest(contestId); this.judge.AddUser(userId); this.judge.AddSubmission(submission); } List <Submission> result = this.judge.GetSubmissions().ToList(); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 550); CollectionAssert.AreEqual(submissions.Values.OrderBy(x => x.Id), result); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { if (contestsByType.ContainsKey(submissionType)) { return(contestsByType[submissionType]); } return(Enumerable.Empty <int>()); }
public IEnumerable <Submission> SubmissionsWithPointsInRangeBySubmissionType( int minPoints, int maxPoints, SubmissionType submissionType) { return(this.bySubmissionId.Values.Where(x => x.Points >= minPoints && x.Points <= maxPoints && x.Type == submissionType)); }
public async Task SubmitCode(Kernel kernel, string[] submissions, SubmissionType submissionType = SubmissionType.Run) { foreach (var submission in submissions) { var cmd = new SubmitCode(submission, submissionType: submissionType); await kernel.SendAsync(cmd); } }
public Submission(int id, int points, SubmissionType type, int contestId, int userId) { this.Id = id; this.Points = points; this.Type = type; this.ContestId = contestId; this.UserId = userId; }
public SubmitCode( string code, string targetKernelName = null, SubmissionType submissionType = SubmissionType.Run) : base(targetKernelName) { Code = code ?? throw new ArgumentNullException(nameof(code)); SubmissionType = submissionType; }
public async Task SubmitCode(KernelBase kernel, string[] codeFragments, SubmissionType submissionType = SubmissionType.Run) { foreach (var codeFragment in codeFragments) { var cmd = new SubmitCode(codeFragment, submissionType: submissionType); await kernel.SendAsync(cmd); } }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { HashSet <int> result = new HashSet <int>(this.judge .Values .Where(x => x.Type == submissionType) .Select(x => x.ContestId)); return(result); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { if (!this.submissions.Values.Any(s => s.Type == submissionType)) { return(new List <int>()); } return(this.submissions.Values.Where(s => s.Type == submissionType).Select(s => s.ContestId).Distinct()); }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { HashSet <int> temp = new HashSet <int>(); if (this.contestsBySubmissionType.ContainsKey(submissionType)) { temp = this.contestsBySubmissionType[submissionType]; } return(temp); }
internal SubmitCode( LanguageNode languageNode, SubmissionType submissionType = SubmissionType.Run, IKernelCommand parent = null) : base(languageNode.Language, parent) { Code = languageNode.Text; SubmissionType = submissionType; SuppressSplit = true; }
public IEnumerable <int> ContestsBySubmissionType(SubmissionType submissionType) { HashSet <int> contests = new HashSet <int>(); foreach (var submission in byType[submissionType]) { contests.Add(submission.ContestId); } return(contests); }
private string GetZoHoTableName(SubmissionType submissionType) { switch (submissionType) { case DMB: return(_config.GetValue <string>("ZoHo:DMBFeedbackTableName")); case Civilians: return(_config.GetValue <string>("ZoHo:CiviliansFeedbackTableName")); default: return(_config.GetValue <string>("ZoHo:DMBFeedbackTableName")); } }
public SubmissionType GetEntityModel(SubmissionType model = null) { model = model ?? new SubmissionType(); model.Id = this.Id; model.Name = this.Name; model.IsSelectedByDefault = this.IsSelectedByDefault; model.ExecutionStrategyType = this.ExecutionStrategyType; model.CompilerType = this.CompilerType; model.AdditionalCompilerArguments = this.AdditionalCompilerArguments; model.Description = this.Description; model.AllowBinaryFilesUpload = this.AllowBinaryFilesUpload; model.AllowedFileExtensions = this.AllowedFileExtensions; return(model); }
public void AddSubmission_SingleSubmissionInvalidContestId_ShouldThrow() { int submissionId = this.idGen.Next(0, 100000); int userId = this.idGen.Next(0, 100000); int contestId = this.idGen.Next(0, 100000); int points = this.idGen.Next(0, 100000); SubmissionType type = (SubmissionType)this.idGen.Next(0, 3); Submission submission = new Submission(submissionId, points, type, contestId, userId); this.judge.AddUser(userId); Assert.Throws <InvalidOperationException>(() => this.judge.AddSubmission(submission)); }
public static void Main() { Judge judge = new Judge(); Dictionary <int, Submission> submissions = new Dictionary <int, Submission>(); for (int i = 0; i < 30000; i++) { int submissionId = i + 1; int userId = i + 1; SubmissionType type = (SubmissionType.CSharpCode); int contestId = i + 1; int points = i + 1; Submission submission = new Submission(submissionId, points, type, contestId, userId); if (!submissions.ContainsKey(submissionId)) { submissions.Add(submissionId, submission); } judge.AddContest(contestId); judge.AddUser(userId); judge.AddSubmission(submission); } var expected = submissions.Values.Where(x => x.UserId == 3).GroupBy(x => x.ContestId).Select(x => x.OrderByDescending(s => s.Points).ThenBy(s => s.Id).First()).OrderByDescending(x => x.Points).ThenBy(x => x.Id).Select(x => x.ContestId); var sw = Stopwatch.StartNew(); IEnumerable <int> result = judge.ContestsByUserIdOrderedByPointsDescThenBySubmissionId(3); sw.Stop(); //Assert.Less(sw.ElapsedMilliseconds, 200); //CollectionAssert.AreEqual(expected, result); Console.WriteLine(sw.ElapsedMilliseconds); foreach (var submission in expected) { Console.WriteLine(submission); } Console.WriteLine("------"); foreach (var submission in result) { Console.WriteLine(submission); } }
private void ValidateBinarySubmission(ModelType model, Problem problem, SubmissionType submissionType) { if (submissionType.AllowBinaryFilesUpload && !string.IsNullOrEmpty(model.ContentAsString)) { this.ModelState.AddModelError("SubmissionTypeId", Resource.Wrong_submision_type); } if (submissionType.AllowedFileExtensions != null) { if (!submissionType.AllowedFileExtensionsList.Contains(model.FileExtension)) { this.ModelState.AddModelError("Content", Resource.Invalid_file_extention); } } }