Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     #region
     Panda ruski = new Panda("Ruski", "*****@*****.**", Gender.male);
     Panda ruski1 = new Panda("One", "*****@*****.**", Gender.male);
     Panda ruski2 = new Panda("Two", "*****@*****.**", Gender.male);
     Panda ruski3 = new Panda("Three", "*****@*****.**", Gender.male);
     Panda ruski4 = new Panda("foure", "*****@*****.**", Gender.male);
     Panda ruski5 = new Panda("Five", "*****@*****.**", Gender.male);
     PandaSocialNetwork pncc = new PandaSocialNetwork();
     pncc.AddPanda(ruski);
     pncc.AddPanda(ruski1);
     pncc.AddPanda(ruski2);
     pncc.AddPanda(ruski3);
     pncc.AddPanda(ruski4);
     pncc.AddPanda(ruski5);
     pncc.MakeFriends(ruski, ruski1);
     pncc.MakeFriends(ruski, ruski2);
     pncc.MakeFriends(ruski2, ruski3);
     pncc.MakeFriends(ruski3, ruski4);
     pncc.MakeFriends(ruski4, ruski5);
     #endregion
     //CommandInterface();
     AreConected(ruski, ruski5);   
 }
 public int ConnectionLevel(Panda one, Panda two)
 {
     if (!(HasPanda(one) && HasPanda(two)))
     {
         return -1;
     }
     List<Panda> visited = new List<Panda>();
     Queue<Panda> pandaQ = new Queue<Panda>();
     Queue<int> levelQ = new Queue<int>();
     pandaQ.Enqueue(one);
     levelQ.Enqueue(0);
     visited.Add(one);
     while (pandaQ.Count>0)
     {
         Panda current = pandaQ.Dequeue();
         int level = levelQ.Dequeue();
         if (current.Equals(two))
         {
             return level;
         }
         foreach (var friend in current.ListP)
         {
             if (!visited.Contains(friend))
             {
                 pandaQ.Enqueue(friend);
                 levelQ.Enqueue(level + 1);
             }
         }
     }
     return -1;
         }
 public void ConnectionLevelTest()
 {
     Panda ruski = new Panda("Ruski", "*****@*****.**", Gender.male);
     Panda ruski1 = new Panda("One", "*****@*****.**", Gender.male);
     Panda ruski2 = new Panda("Two", "*****@*****.**", Gender.male);
     Panda ruski3 = new Panda("Three", "*****@*****.**", Gender.male);
     Panda ruski4 = new Panda("foure", "*****@*****.**", Gender.male);
     Panda ruski5 = new Panda("Five", "*****@*****.**", Gender.male);
     PandaSocialNetwork pncc = new PandaSocialNetwork();
     pncc.AddPanda(ruski);
     pncc.AddPanda(ruski1);
     pncc.AddPanda(ruski2);
     pncc.AddPanda(ruski3);
     pncc.AddPanda(ruski4);
     pncc.AddPanda(ruski5);
     pncc.MakeFriends(ruski, ruski1);
     pncc.MakeFriends(ruski, ruski2);
     pncc.MakeFriends(ruski2, ruski3);
     pncc.MakeFriends(ruski2, ruski4);
     pncc.MakeFriends(ruski2, ruski5);
     if (!(pncc.ConnectionLevel(ruski, ruski1) == 1 && pncc.ConnectionLevel(ruski1, ruski5) == 3))
     {
         Assert.Fail();
     }
 }
 public bool AreConnected(Panda one,Panda two)
 {
     if (ConnectionLevel(one,two) != -1)
         {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 public void EqualsTest()
 {
     Panda ruski = new Panda("Ivan", "*****@*****.**", Gender.male);
     if (!(ruski.Name == "Ivan" && ruski.Email == "*****@*****.**" && ruski.Gender == Gender.male))
     {
         Assert.Fail();
     }
 }
 public void AddPandaTest()
 {
     Panda pnd = new Panda("Ruski", "*****@*****.**", Gender.male);
     PandaSocialNetwork network = new PandaSocialNetwork();
     network.AddPanda(pnd);
     if (!network.HasPanda(pnd))
     {
         Assert.Fail();
     }
 }
 public void AddPanda(Panda newpanda)
 {
     if (pandas.Contains(newpanda))
     {
         throw new PandaAlreadyThereException();
     }
     else
     {
         pandas.Add(newpanda);
     }
 }
 public List<Panda> FriendsOf(Panda panda)
 {
     if (pandas.Contains(panda))
     {
         throw new Exception();//TO DO CUSTOM EXC NOTINTHENEWTROK
     }
     else
     {
         return panda.ListP;
     }
 }
Ejemplo n.º 9
0
 public void TestEmailProperty()
 {
     try
     {
         //Inserting correct email format
         Panda ruski = new Panda("Ivan", "*****@*****.**", Gender.male);
     }
     catch (IncorrectFormatEmailExcception)
     {
         Assert.Fail();
     }
 }
 public void MakeFriendsTest()
 {
     Panda one = new Panda("Ruski", "*****@*****.**", Gender.male);
     Panda two = new Panda("Ivan", "*****@*****.**", Gender.male);
     PandaSocialNetwork network = new PandaSocialNetwork();
     network.AddPanda(one);
     network.AddPanda(two);
     network.MakeFriends(one, two);
     List<Panda> friend = network.FriendsOf(one);
     if (!friend.Contains(two))
     {
         Assert.Fail();
     }
 }
Ejemplo n.º 11
0
 public void PandaTestEmailPropertyChecker()
 {
     try
     {
         //Inserting Wrong email format
         Panda ruski = new Panda("Ivan", "rbv.bg", Gender.male);
         Assert.Fail();
     }
     catch (IncorrectFormatEmailExcception)
     {
         throw new IncorrectFormatEmailExcception();
     }
     
 }
        public void TestSaveAndLoad()
        {
            Panda ruski = new Panda("Ruski", "*****@*****.**", Gender.male);

            PandaSocialNetwork newtowrkOne = new PandaSocialNetwork();
            newtowrkOne.AddPanda(ruski);
            SavennLoadNetwork svn = new SavennLoadNetwork();
            svn.Save(newtowrkOne);
            PandaSocialNetwork two = svn.Load();
            if (!(two.Members.Contains(ruski) == (newtowrkOne.Members.Contains(ruski))))
            {
                Assert.Fail();
            }


        }
Ejemplo n.º 13
0
     static void Main(string[] args)
     {
         Panda ruski = new Panda("Ruski", "*****@*****.**", Gender.male);
         Panda ruski1 = new Panda("One", "*****@*****.**", Gender.male);
         Panda ruski2= new Panda("Two", "*****@*****.**", Gender.male);
         Panda ruski3 = new Panda("Three", "*****@*****.**", Gender.male);
         Panda ruski4 = new Panda("foure", "*****@*****.**", Gender.male);
         Panda ruski5 = new Panda("Five", "*****@*****.**", Gender.male);
         PandaSocialNetwork pncc = new PandaSocialNetwork();
         pncc.AddPanda(ruski);
         pncc.AddPanda(ruski1);
         pncc.AddPanda(ruski2);
         pncc.AddPanda(ruski3);
         pncc.AddPanda(ruski4);
         pncc.AddPanda(ruski5);
 
         pncc.MakeFriends(ruski, ruski2);
         pncc.MakeFriends(ruski2, ruski3);
         pncc.MakeFriends(ruski3, ruski4);
         pncc.MakeFriends(ruski4, ruski5);
         Console.WriteLine(pncc.ConnectionLevel(ruski1, ruski5));
         Console.WriteLine(pncc.AreConnected(ruski1,ruski5));
     }
Ejemplo n.º 14
0
 public static int AreConected(Panda one, Panda two)
 {
     HashSet<Panda> visited = new HashSet<Panda>();
     Queue<Panda> pand = new Queue<Panda>();
     pand.Enqueue(one);
     visited.Add(one);
     Console.WriteLine(pand.Peek());
     while (pand.Count>0)
     {
         Panda curr = pand.Dequeue();
         foreach (var item in curr.ListP)
         {
             if (!visited.Contains(item))
             {
                 Console.WriteLine(item.ToString());
                 visited.Add(item);
                 pand.Enqueue(item);
             }
         }
         
     }
     return 0;
 }
Ejemplo n.º 15
0
 public void Befriend(Panda panda)
 {
     if (ListP.Contains(panda))
     {
         throw new Exception();///TO DO CUSTOM EXC
     }
     ListP.Add(panda);
 }
        public List<Panda> FriendsOf(Panda panda)
        {
            return panda.ListP;

        }
Ejemplo n.º 17
0
 public void Befriend(Panda panda)
 {
     if (ListP.Contains(panda))
     {
         throw new AlreadyFriendException();
     }
     ListP.Add(panda);
 }
 public int HowManyGenderInNetwork(int level, Panda PandaForFriends, Gender gender)
 {
     int genderInLevel = 0;
     if (PandaForFriends.Gender == gender)
     {
         genderInLevel++;
     }
     foreach (var pnd in PandaForFriends.ListP)
     {
         if (ConnectionLevel(PandaForFriends, pnd) >= level)
         {
             break;
         }
         if (pnd.Gender == gender)
         {
             genderInLevel++;
         }
     }
     return genderInLevel;
 }
Ejemplo n.º 19
0
        private static void CommandInterface()
        {

            string[] listOFComands = {"add panda in the network",
                                      "hasPanda",
                                      "make friends",
                                      "are friends (panda1 panda2)",
                                      "friends of (Panda)",
                                      "connection level (panda1 panda2)",
                                      "show genders all to level",
                                      "close"};
            Console.WriteLine("List of commands");
            foreach (var item in listOFComands)
            {

                Console.WriteLine(item);
            }
            string command = string.Empty;
            PandaSocialNetwork network = new PandaSocialNetwork();
            while (true)
            {
                command = Console.ReadLine();
                if (command == "add panda in the network")
                {
                    Panda newPanda = new Panda();
                    Console.Write("Enter Panda name: ");
                    command = Console.ReadLine();
                    newPanda.Name = command;
                    Console.Write("Enter Panda email: ");
                    command = Console.ReadLine();
                    newPanda.Email = command;
                    Console.Write("Enter panda gender: ");
                    command = Console.ReadLine();
                    if (command == Gender.male.ToString())
                    {
                        newPanda.Gender = Gender.male;
                    }
                    else
                    {
                        newPanda.Gender = Gender.female;
                    }
                    network.AddPanda(newPanda);
                }
                else if (command == "hasPanda")
                {
                    Console.Write("What is the name of the panda you are searching for ");
                    command = Console.ReadLine();
                    Panda temp = new Panda();
                    foreach (var item in network.Members)
                    {
                        if (command == item.Name)
                        {
                            temp = item;
                            break;
                        }
                    }
                    if (network.HasPanda(temp))
                    {
                        Console.WriteLine($"The panda \"{temp.Name}\" is in the newtwork. ");
                    }
                    else
                    {
                        Console.WriteLine($"The panda \"{temp.Name}\" is not  in the newtwork.\n Would you like to add it to the network");
                        command = Console.ReadLine();
                        if (command == "yes")
                        {
                            network.AddPanda(temp);
                        }
                        Console.WriteLine("DONE!");
                    }
                }
                else if (command == "make friends")
                {
                    Console.Write("Which pandas you want to become friends");
                    command = Console.ReadLine();
                    string[] pands = command.Split(' ');
                    bool foundFirst = false;
                    bool foundSecond = false;
                    foreach (var panda in network.Members)
                    {
                        if (panda.Name == pands[0])
                        {
                            foundFirst = true;
                            foreach (var pandaTwo in network.Members)
                            {
                                if (pandaTwo.Name == pands[1])
                                {
                                    panda.Befriend(pandaTwo);
                                    pandaTwo.Befriend(panda);
                                    foundSecond = true;
                                }
                            }
                        }
                    }
                    if (!foundFirst)
                    {
                        Console.WriteLine($"We coulnd find member {pands[0]}");
                    }
                    if (!foundSecond)
                    {
                        Console.WriteLine($"We coulnd find member {pands[1]}");
                    }
                }
                else if (command.Contains("are friends"))
                {
                    string[] pandaNames = command.Split(' ');
                    string pandaOne = pandaNames[2];
                    string pandatwo = pandaNames[3];
                    foreach (var panda in network.Members)
                    {
                        if (panda.Name == pandaOne)
                        {
                            foreach (var pandTwo in network.Members)
                            {
                                if (pandTwo.Name == pandatwo)
                                {
                                    if (panda.ListP.Contains(pandTwo))
                                    {
                                        Console.WriteLine("They are friends");
                                    }
                                    else
                                    {
                                        Console.WriteLine("They are not friends");
                                    }
                                }
                            }
                        }
                    }
                }
                else if (command.Contains("friends of"))
                {
                    string[] panda = command.Split(' ');
                    bool isFound = false;
                    foreach (var item in network.Members)
                    {
                        if (item.Name == panda[3])
                        {
                            isFound = true;
                            foreach (var fr in item.ListP)
                            {
                                Console.WriteLine(fr.ToString());
                            }
                        }
                    }
                    if (!isFound)
                    {
                        Console.WriteLine("There is no such panda in the network");
                    }
                }
                else if (command.Contains("connection level"))
                {
                    string[] pandas = command.Split(' ');
                    bool isFoundOne = false;
                    bool isFoundTwo = false;
                    foreach (var pandaOne in network.Members)
                    {
                        if (pandaOne.Name == pandas[3])
                        {
                            isFoundOne = true;
                            foreach (var pandaTWo in network.Members)
                            {
                                if (pandas[4] == pandaTWo.Name)
                                {
                                    isFoundTwo = true;
                                    int connect = network.ConnectionLevel(pandaOne, pandaTWo);
                                    Console.WriteLine($"Connection level between {pandas[3]} and {pandas[4]} is {connect}");
                                    break;
                                }
                            }
                        }
                    }
                    if (!isFoundOne)
                    {
                        Console.WriteLine($"{pandas[3]} is not found");
                    }
                    if (!isFoundTwo)
                    {
                        Console.WriteLine($"{pandas[4]} is not found");
                    }
                }
                else if (command.Contains("show genders all to level"))
                {
                    string[] str = command.Split(' ');
                    int level = int.Parse(str[5]);
                    Console.WriteLine("male or female");
                    command = Console.ReadLine();
                    if (command == "male")
                    {
                        Console.WriteLine(network.HowManyGenderInNetwork(level, Gender.male));
                    }
                    else
                    {
                        Console.WriteLine(network.HowManyGenderInNetwork(level, Gender.female));
                    }
                }
                else if (command == "close")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Wrong Command try Again");
                }

            }
        }
 public bool HasPanda(Panda panda)
 {
     return Members.Contains(panda);
 }
 public bool AreFriends(Panda one, Panda two)
 {
     return one.ListP.Contains(two);
 }
 public void MakeFriends(Panda one, Panda two)
 {
     one.Befriend(two);
     two.Befriend(one);
 }
 public bool HasPanda(Panda panda)
 {
     return pandas.Contains(panda);
 }