Exemplo n.º 1
0
    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);
        }
    }
Exemplo n.º 2
0
    public static void Main()
    {
        Dictionary <int, Submission> submissions = new Dictionary <int, Submission>();
        var idGen = new Random();
        var judge = new Judge();

        for (int i = 0; i < 500; i++)
        {
            int            submissionId = idGen.Next(0, 100000);
            int            userId       = idGen.Next(0, 5);
            SubmissionType type         = (SubmissionType)idGen.Next(0, 3);
            int            contestId    = idGen.Next(0, 15);
            int            points       = idGen.Next(0, 30);

            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);

        IEnumerable <int> result = judge.ContestsByUserIdOrderedByPointsDescThenBySubmissionId(3);

        ;
    }
Exemplo n.º 3
0
    public static void Main()
    {
        var judge = new Judge();;
        var idGen = new Random();

        Dictionary <int, Submission> submissions = new Dictionary <int, Submission>();
        List <int> ids = new List <int>();

        for (int i = 0; i < 500; i++)
        {
            int            submissionId = idGen.Next(0, 100000);
            int            userId       = idGen.Next(0, 5);
            SubmissionType type         = (SubmissionType)idGen.Next(0, 3);
            int            contestId    = idGen.Next(0, 5);
            int            points       = idGen.Next(0, 5);

            Submission submission = new Submission(submissionId, points, type, contestId, userId);

            if (!submissions.ContainsKey(submissionId))
            {
                submissions.Add(submissionId, submission);
                ids.Add(submissionId);
            }

            judge.AddContest(contestId);
            judge.AddUser(userId);
            judge.AddSubmission(submission);
        }

        int        subId = idGen.Next(0, ids.Count);
        Submission sub   = submissions[ids[subId]];

        IEnumerable <Submission> result = judge.SubmissionsInContestIdByUserIdWithPoints(sub.Points,
                                                                                         sub.ContestId, sub.UserId);

        IEnumerable <Submission> expectedResult = submissions.Values.Where(x => x.ContestId == sub.ContestId &&
                                                                           x.UserId == sub.UserId &&
                                                                           x.Points == sub.Points);
    }