public void AddPandaTest()
 {
     Panda pnd = new Panda("Ruski", "*****@*****.**", Gender.male);
     PandaSocialNetwork network = new PandaSocialNetwork();
     network.AddPanda(pnd);
     if (!network.HasPanda(pnd))
     {
         Assert.Fail();
     }
 }
Example #2
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");
                }

            }
        }