Пример #1
0
        public void TestCalculateCompetitionPoints()
        {
            var diver = new Diver(3, "Johan", "Sweden", 23, "Man", 365);
            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(1, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(1, 1.2f, 0, 3, diver.DiverId);
            var dive4 = new Dive(1, 3.0f, 0, 4, diver.DiverId);
            var dive5 = new Dive(1, 4.7f, 0, 5, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);
            diver.AddDive(dive4);
            diver.AddDive(dive5);

            Assert.AreEqual(5, diver.ListDive.Count);

            var score1 = new Score(5.5f);
            var score2 = new Score(2.5f);
            var score3 = new Score(8.0f);
            var score4 = new Score(5.0f);
            var score5 = new Score(2.5f);

            var allRefScores = new List<Score> { score1, score2, score3, score4, score5 };

            diver.ListDive[0].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[0].Type.Difficulty);
            diver.ListDive[1].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[1].Type.Difficulty);
            diver.ListDive[2].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[2].Type.Difficulty);
            diver.ListDive[3].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[3].Type.Difficulty);
            diver.ListDive[4].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[4].Type.Difficulty);

            diver.SummarizeDivePoints();

            //Assert.AreEqual(243.1, Math.Round(diver._competitionScore, 2));
        }
Пример #2
0
 public void TestAddDive()
 {
     var testDiver = new Diver();
     testDiver.AddDive(new Dive(1, (float)3.5, 0, 1, testDiver.DiverId));
     testDiver.AddDive(new Dive(2, (float)5.5, 0, 2, testDiver.DiverId));
     Assert.AreEqual(testDiver.ListDive[0].Type.Difficulty, 3.5);
     Assert.AreEqual(testDiver.ListDive[1].Type.Difficulty, 5.5);
 }
Пример #3
0
        public void SerializeTest()
        {
            var diver = new Diver(5, "Körberg", "Finland", 105, "Kvinna", 9);
            var seriObject = Serializer.Serialize(diver);

            var deseriObject = Serializer.Deserialize(seriObject);

            Assert.AreEqual("Körberg", ((Diver)deseriObject).Name);
            Assert.AreEqual("Finland", ((Diver)deseriObject).Country);
        }
Пример #4
0
 public void TestAddDiveList()
 {
     var testDiver = new Diver();
     var testDiveList = new List<Dive>
     {
         new Dive(1, 3.3f, 0, 1, testDiver.DiverId),
         new Dive(2, 4.4f, 0, 2, testDiver.DiverId)
     };
     testDiver.AddDiveList(testDiveList);
     Assert.AreEqual(testDiver.ListDive[0].Type.Difficulty, 3.3f);
     Assert.AreNotEqual(testDiver.ListDive[1].Type.Difficulty, 5.5f);
 }
Пример #5
0
 /// <summary>
 ///     Tillagd funktion för att checka att en hoppare har fullständig information
 /// </summary>
 /// <param name="diver"></param>
 /// <returns></returns>
 public static bool CheckCompleteDiver(Diver diver)
 {
     if (diver.Age == -1)
         return false;
     if (diver.DiverId == -1)
         return false;
     if (diver.Gender == "")
         return false;
     if (diver.Name == "")
         return false;
     if (diver.Country == "")
         return false;
     if (diver.Id == -1)
         return false;
     return true;
 }
Пример #6
0
        public void TestCreateDiver()
        {
            var diver = new Diver(3, "Johan", "Sweden", 23, "Man", 365);
            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(1, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(1, 1.2f, 0, 3, diver.DiverId);
            var dive4 = new Dive(1, 3.0f, 0, 4, diver.DiverId);
            var dive5 = new Dive(1, 4.7f, 0, 5, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);
            diver.AddDive(dive4);
            diver.AddDive(dive5);

            Assert.AreEqual(5, diver.ListDive.Count);
        }
Пример #7
0
        public void TestDiverTotalScore()
        {
            var diver = new Diver(1, "Fred", "S", 23, "M", 23);
            Assert.IsTrue(diver.CompetitionScore.Value == 0f);

            var dives = new List<Dive>
            {
                new Dive(1, 1.5f, 5.0f, 1, 23),
                new Dive(2, 1.5f, 6.0f, 2, 23),
                new Dive(3, 1.5f, 7.0f, 3, 23),
                new Dive(4, 1.5f, 8.0f, 4, 23)
            };

            diver.AddDiveList(dives);
            Assert.AreEqual(diver.SummarizeDivePoints().Value, diver.CompetitionScore.Value);

            Assert.AreEqual(26f, diver.CompetitionScore.Value);
        }
Пример #8
0
        public void AddDiverToCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 6);
            var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3);

            competitionObject.AddDiver(diver);
            Assert.AreEqual(1, competitionObject.ListDiver.Count);

            competitionObject.AddDiver(diver);
            Assert.AreEqual(1, competitionObject.ListDiver.Count);

            var diver2 = new Diver(7, "Stefan", "Uganda", 14, "Man", 6);

            competitionObject.AddDiver(diver2);
            Assert.AreEqual(2, competitionObject.ListDiver.Count);

            var diver3 = new Diver();

            competitionObject.AddDiver(diver3);
            Assert.AreEqual(2, competitionObject.ListDiver.Count);
        }
Пример #9
0
        public static void AddDiversToCompetition(int rounds)
        {
            DisplayDivers();
            while (Creating)
            {
                try
                {
                    var listContains = false;
                    var tDiver = new Diver();
                    var choice = ChooseDiver();
                    if (choice == 0)
                    {
                        Creating = false;
                        break;
                    }
                    // Lägga till kontroll för hur många divers som lagts till?
                    foreach (var diver in TempCompetition.ListDiver)
                    {
                        // Kollar om diver redan är tillagd
                        if (choice == diver.DiverId)
                        {
                            listContains = true;
                            break;
                        }
                    }

                    // Lägger till diver om denne inte finns i listan
                    if (!listContains)
                    {
                        foreach (var diver in AllDivers)
                        {
                            if (diver.DiverId == choice)
                            {
                                tDiver = diver;
                                AddDives(tDiver, rounds);
                                break;
                            }
                        }
                        if (tDiver.DiverId == -1)
                            throw new ListObjectNotFoundException("Diver not found!");
                    }
                    else
                    {
                        throw new ListObjectAlreadyExistsException("Diver already added!");
                    }
                }
                catch (ListObjectNotFoundException e)
                {
                    WriteLine(e.Message);
                    Thread.Sleep(1000);
                }
                catch (ListObjectAlreadyExistsException e)
                {
                    WriteLine(e.Message);
                    Thread.Sleep(1000);
                }
                catch (FormatException formatException)
                {
                    WriteLine(formatException.Message);
                    Thread.Sleep(1000);
                }
            }
        }
Пример #10
0
        public static void InsertDiver(Diver diver)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "INSERT INTO diver (Name, Age, Worldrank, Country, Gender, DiverId) " +
                               "VALUES (@name, @age, @worldRank, @country, @gender, @diverId)";

            using (var sqlConnection = ConnectToDatabase())
            {
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    sqlQuery.Parameters.AddWithValue("@name", diver.Name);
                    sqlQuery.Parameters.AddWithValue("@age", diver.Age);
                    sqlQuery.Parameters.AddWithValue("@worldRank", diver.Rank);
                    sqlQuery.Parameters.AddWithValue("@country", diver.Country);
                    sqlQuery.Parameters.AddWithValue("@gender", diver.Gender);
                    sqlQuery.Parameters.AddWithValue("@diverId", diver.DiverId);

                    var result = sqlQuery.ExecuteNonQuery();
                    Logger.Info("{0} rows affected", result);
                }
            }
            Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
        }
Пример #11
0
        public static List<Diver> GetDivers()
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "SELECT * FROM diver";

            using (var sqlConnection = ConnectToDatabase())
            {
                var diverList = new List<Diver>();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var diver = new Diver(
                            tableReader.GetInt32("ID"),
                            tableReader.GetString("Name"),
                            tableReader.GetString("Country"),
                            tableReader.GetInt32("Age"),
                            tableReader.GetString("Gender"),
                            tableReader.GetInt32("DiverId"));
                        diverList.Add(diver);
                    }
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return diverList;
            }
        }
Пример #12
0
 public void AddDiver(Diver diver)
 {
     SendToServer(diver);
 }
Пример #13
0
        public void OnAddDiverToDatabase(object source, EventArgs args)
        {
            if (IsNullOrEmpty(AddDiver.nameBox.Text) ||
                IsNullOrEmpty(AddDiver.CountryBox.Text) ||
                IsNullOrEmpty(AddDiver.AgeBox.Text) ||
                IsNullOrEmpty(AddDiver.diverIDBox.Text))
            {
                ErrorMessageBox("Fyll i samtliga fält", "Vänligen fyll i alla fält");
                return;
            }
            var admin = new Admin();
            var genderChoice = "";
            if (AddDiver.radioMan.Checked)
                genderChoice = "M";
            else if (AddDiver.radioWoman.Checked)
                genderChoice = "F";

            var diver = new Diver(
                AddDiver.nameBox.Text, AddDiver.CountryBox.Text,
                int.Parse(AddDiver.AgeBox.Text), genderChoice,
                int.Parse(AddDiver.diverIDBox.Text));
            admin.AddDiver(diver);
            MessageBox.Show(
                "Hoppare tillagd till databasen!",
                "Hoppare tillagd", MessageBoxButtons.OK);
            AddDiver.Close();
        }
Пример #14
0
        /// <summary>
        ///     Kollar om det finns en diver i listan, annars läggs den till
        ///     Kontrollerar så inga tomma objekt läggs till
        /// </summary>
        /// <param name="diver"></param>
        public void AddDiver(Diver diver)
        {
            var contains = false;

            if (CheckCompleteDiver(diver))
            {
                foreach (var dvr in ListDiver.Where(dvr => diver == dvr))
                {
                    contains = true;
                }

                if (contains)
                {
                    Console.Write("Diver is already in list!");
                }
                else
                {
                    ListDiver.Add(diver);
                }
            }
        }
Пример #15
0
 private static void AddDives(Diver tempDiver, int rounds)
 {
     WriteLine("Enter details of dives for {0}:", tempDiver.Name);
     for (var i = 1; i <= rounds; i++)
     {
         var dive = new Dive();
         WriteLine($"Dive number {i}:");
         WriteLine("Dive code: ");
         dive.Type.Code = ReadLine();
         try
         {
             if (!tempDiver.ListDive.Contains(dive))
                 tempDiver.AddDive(dive);
             else
             {
                 i--;
                 throw new ListObjectAlreadyExistsException("Dive already added!");
             }
         }
         catch (ListObjectAlreadyExistsException e)
         {
             WriteLine(e.Message);
         }
     }
     TempCompetition.AddDiver(tempDiver);
     WriteLine("Diver {0} added!", tempDiver.Name);
     Thread.Sleep(2000);
 }
Пример #16
0
 public static Diver CreateDiver()
 {
     Clear();
     var diver = new Diver();
     WriteLine("Enter diver details:");
     Write("Name: ");
     diver.Name = ReadLine();
     Write("Country: ");
     diver.Country = ReadLine();
     Write("Gender: ");
     diver.Gender = ReadLine();
     Write("Age: ");
     diver.Age = Convert.ToInt32(ReadLine());
     Write("DiverId: ");
     diver.DiverId = Convert.ToInt32(ReadLine());
     WriteLine("\n");
     return diver;
 }
Пример #17
0
        public static Diver GetDiver(int diverId)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            var sql = $"SELECT * FROM diver WHERE ID = {diverId}";

            using (var sqlConnection = ConnectToDatabase())
            {
                var diver = new Diver();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var tempDiver = new Diver(
                            tableReader.GetInt32("Id"),
                            tableReader.GetString("Name"),
                            tableReader.GetString("Country"),
                            tableReader.GetInt32("Age"),
                            tableReader.GetString("Gender"),
                            tableReader.GetInt32("DiverId"));
                        diver = tempDiver;
                    }
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return diver;
            }
        }
Пример #18
0
        public void TestFullCompetition()
        {
            var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 3);

            var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3);
            var diver2 = new Diver(5, "Susanna", "Sweden", 27, "Kvinna", 12);
            var diver3 = new Diver(2, "Klas-Göran", "Sweden", 22, "Man", 321);
            competitionObject.AddDiver(diver);
            competitionObject.AddDiver(diver2);
            competitionObject.AddDiver(diver3);

            Assert.AreEqual(3, competitionObject.ListDiver.Count);

            var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId);
            var dive2 = new Dive(2, 6.2f, 0, 2, diver.DiverId);
            var dive3 = new Dive(3, 1.2f, 0, 3, diver.DiverId);
            diver.AddDive(dive1);
            diver.AddDive(dive2);
            diver.AddDive(dive3);

            var dive4 = new Dive(4, 2.6f, 0, 1, diver2.DiverId);
            var dive5 = new Dive(5, 3.7f, 0, 2, diver2.DiverId);
            var dive6 = new Dive(6, 9.2f, 0, 3, diver2.DiverId);
            diver2.AddDive(dive4);
            diver2.AddDive(dive5);
            diver2.AddDive(dive6);

            var dive7 = new Dive(7, 4.9f, 0, 1, diver3.DiverId);
            var dive8 = new Dive(8, 6.2f, 0, 2, diver3.DiverId);
            var dive9 = new Dive(9, 1.2f, 0, 3, diver3.DiverId);
            diver3.AddDive(dive7);
            diver3.AddDive(dive8);
            diver3.AddDive(dive9);

            if (competitionObject.CheckIfSameAmountOfDives())
            {
                var allRefScores = new List<Score>();
                var score1 = new Score(5.5f);
                var score2 = new Score(2.5f);
                var score3 = new Score(8.0f);
                var score4 = new Score(5.0f);
                var score5 = new Score(2.5f);
                allRefScores.Add(score1);
                allRefScores.Add(score2);
                allRefScores.Add(score3);
                allRefScores.Add(score4);
                allRefScores.Add(score5);
                for (var i = 0; i < competitionObject.Rounds; i++)
                {
                    foreach (var contestant in competitionObject.ListDiver)
                    {
                        contestant.ListDive[i].TotalPoints.CalculateCompleteScore(allRefScores, contestant.ListDive[i].Type.Difficulty);
                    }
                }
                foreach (var contestant in competitionObject.ListDiver)
                {
                    contestant.SummarizeDivePoints();
                }
                Assert.AreEqual("Susanna", competitionObject.GetWinner());
            }
        }
Пример #19
0
 public void AddDivetoDiver(Diver diver, Dive dive)
 {
     foreach (var dvr in ListDiver.Where(dvr => dvr == diver))
     {
         dvr.AddDive(dive);
         break;
     }
 }