Exemplo n.º 1
0
        public void ContestEvaluationObject_InitializedCorrectly()
        {
            //act
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //verify
            Assert.That(sut.ElectionResultsFileName, Is.EqualTo(electionResultsFile));
            Assert.That(sut.ProvidedTipsFileName, Is.EqualTo(providedTipsFile));
        }
Exemplo n.º 2
0
        public void CountScore_CountOfEvaluatedTips()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3);

            //verify
            Assert.That(result.Count, Is.EqualTo(2), "Count of evaluated tips must fit the count of provided tips.");
        }
Exemplo n.º 3
0
        public void CountScore_ReturnsTypeOfEvaluatedTips()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3);

            //verify
            Assert.That(result, Is.TypeOf <EvaluatedTips>());
        }
Exemplo n.º 4
0
        public void CountScore_ResultDoesNotContainNotExistingTipperName()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3);

            //verify
            string notExistingTipperName = "NoSuchTipper";

            Assert.IsFalse(result.Any(x => x.TipperName.Equals(notExistingTipperName)),
                           $"Evaluated tips must NOT contain a tip with TipperName {notExistingTipperName}.");
        }
Exemplo n.º 5
0
        public void CountScore_ResultsAreOrderedFromBestScore()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3).OrderBy(x => x.Score).ToList();

            //verify
            Assert.That(result[0].Score, Is.EqualTo(-10),
                        $"On first position must be tipper with best score.");
            Assert.That(result[1].Score, Is.EqualTo(15),
                        $"On second position must be tipper with second best score.");
        }
Exemplo n.º 6
0
        public void CountScore_ScoreIsCountedCorrectly()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3);

            //verify
            Assert.That(result[0].Score, Is.EqualTo(15),
                        $"Score for tipper '{result[0].TipperName}' not counted correctly.");
            Assert.That(result[1].Score, Is.EqualTo(-10),
                        $"Score for tipper '{result[1].TipperName}' not counted correctly.");
        }
Exemplo n.º 7
0
        public void CountScore_ResultContainsNameOfTipper()
        {
            //prepare
            var sut = new ContestEvaluation(electionResultsFile, providedTipsFile);

            //act
            var result = sut.CountScore(5, 3);

            //verify
            string expectedTipperNameOne = "Lubo";

            Assert.IsTrue(result.Any(x => x.TipperName.Equals(expectedTipperNameOne)),
                          $"Evaluated tips must contain a tip with TipperName {expectedTipperNameOne}.");
            string expectedTipperNameTwo = "Miso";

            Assert.IsTrue(result.Any(x => x.TipperName.Equals(expectedTipperNameTwo)),
                          $"Evaluated tips must contain a tip with TipperName {expectedTipperNameTwo}.");
        }
Exemplo n.º 8
0
        public void Count_RealResults_ForParliamentElections2020()
        {
            //prepare
            var realElectionResultsFile = FilePathProvider.ProvideFullPathToFile("ParliamentElections2020Results.json", @"Source\PresidentElection\InputData");
            var realTipsFile            = FilePathProvider.ProvideFullPathToFile("ParliamentElections2020Tips.json", @"Source\PresidentElection\InputData");
            var sut = new ContestEvaluation(realElectionResultsFile, realTipsFile);

            //act
            var result = sut.CountScore(1, 6).OrderBy(x => x.Score).ToList();
            int i      = 0;

            Console.WriteLine("{0} {1,6} {2,7}", "Place", "Name", "Score");
            Console.WriteLine("--------------------");
            foreach (var evaluatedTip in result)
            {
                Console.WriteLine($"{++i,3}. {evaluatedTip.TipperName,7} {evaluatedTip.Score,7}");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// This method retrieves all the judge votes from the database.
        /// </summary>
        private void GetContestVotes()
        {
            List <JudgeEvaluation> judgeEvaluations = new List <JudgeEvaluation>();

            string query = "SELECT id_user, id_criteria1, id_criteria2, value FROM contest_juri_criteria_table " +
                           "WHERE id_contest = @id_contest " +
                           "ORDER BY id_criteria1 ASC, id_criteria2 ASC";

            SqlCommand cmd = DBSqlHelper.Connection.CreateCommand();

            cmd.CommandText = query;

            cmd.Parameters.Add(new SqlParameter("@id_contest", contest.Id));

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int userId, userIndex;

                while (reader.Read())
                {
                    userIndex = -1;

                    userId = reader.GetInt32(0);

                    userIndex = judgeEvaluations.FindIndex(user => user.JudgeId == userId);

                    if (userIndex >= 0)
                    {
                        judgeEvaluations[userIndex].CriteriaEvaluations.Add(new CriteriaEvaluation
                        {
                            Criteria1 = new Criteria(reader.GetInt32(1), "", ""),
                            Criteria2 = new Criteria(reader.GetInt32(2), "", ""),
                            Value     = reader.GetInt32(3)
                        });
                    }
                    else
                    {
                        judgeEvaluations.Add(new JudgeEvaluation
                        {
                            JudgeId             = userId,
                            CriteriaEvaluations = new List <CriteriaEvaluation>()
                            {
                                new CriteriaEvaluation
                                {
                                    Criteria1 = new Criteria(reader.GetInt32(1), "", ""),
                                    Criteria2 = new Criteria(reader.GetInt32(2), "", ""),
                                    Value     = reader.GetInt32(3)
                                }
                            }
                        });
                    }
                }
            }

            query = "SELECT id_user, id_project1, id_project2, id_criteria, value FROM evaluation_table " +
                    "WHERE id_contest = @id_contest " +
                    "ORDER BY id_criteria ASC, id_project1 ASC, id_project2 ASC";

            cmd             = DBSqlHelper.Connection.CreateCommand();
            cmd.CommandText = query;

            cmd.Parameters.Add(new SqlParameter("@id_contest", contest.Id));

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                int userId, userIndex;

                while (reader.Read())
                {
                    userIndex = -1;

                    userId = reader.GetInt32(0);

                    userIndex = judgeEvaluations.FindIndex(user => user.JudgeId == userId);

                    if (userIndex >= 0)
                    {
                        judgeEvaluations[userIndex].ProjectEvaluations.Add(new ProjectEvaluation
                        {
                            Criteria = new Criteria(reader.GetInt32(3), "", ""),
                            Project1 = new Project(reader.GetInt32(1), "", "", new Category(), -1),
                            Project2 = new Project(reader.GetInt32(2), "", "", new Category(), -1),
                            Value    = reader.GetInt32(4)
                        });
                    }
                    else
                    {
                        judgeEvaluations.Add(new JudgeEvaluation
                        {
                            JudgeId            = userId,
                            ProjectEvaluations = new List <ProjectEvaluation>()
                            {
                                new ProjectEvaluation
                                {
                                    Criteria = new Criteria(reader.GetInt32(3), "", ""),
                                    Project1 = new Project(reader.GetInt32(1), "", "", new Category(), -1),
                                    Project2 = new Project(reader.GetInt32(2), "", "", new Category(), -1),
                                    Value    = reader.GetInt32(4)
                                }
                            }
                        });
                    }
                }
            }

            // Now let's add all the judge evaluations to the contest evaluation.
            contestEvaluation = new ContestEvaluation
            {
                JudgeEvaluations = judgeEvaluations
            };

            // Get number of criterias from database.
            query = "SELECT COUNT(*) FROM contest_criteria_table WHERE id_contest = @id_contest";

            cmd             = DBSqlHelper.Connection.CreateCommand();
            cmd.CommandText = query;

            cmd.Parameters.Add(new SqlParameter("@id_contest", contest.Id));

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();

                criteriaCount = reader.GetInt32(0);
            }

            // Get number of projects from database.
            query = "SELECT COUNT(*) FROM project_table WHERE id_contest = @id_contest";

            cmd             = DBSqlHelper.Connection.CreateCommand();
            cmd.CommandText = query;

            cmd.Parameters.Add(new SqlParameter("@id_contest", contest.Id));

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();

                projectCount = reader.GetInt32(0);
            }
        }