Exemple #1
0
            public void AssertAbilityToAddNewBornToLavanya()
            {
                Ape lavnya = _apeService.GetElement("Lavnya");

                Assert.That(new List <Ape>(), Is.EqualTo(lavnya.GetChildren(GenderType.Female, _apeFamilyService)));

                ApeFamily apeFamily = _apeFamilyService.GetAll().SingleOrDefault(p => p.Partners.Contains(lavnya));
                Ape       newBorn   = apeFamily?.AddNewBorn("Vanya", lavnya.GetDepthLevel() + 1, GenderType.Female);

                _apeFamilyAssociationService.AddElement(newBorn?.GetName(), apeFamily);
                _apeService.AddElement(newBorn?.GetName(), newBorn);

                Ape vanya = _apeService.GetElement("Vanya");

                Assert.That(new List <Ape>()
                {
                    vanya
                }, Is.EqualTo(lavnya.GetChildren(GenderType.Female, _apeFamilyService)));

                Ape jnki = _apeService.GetElement("Jnki");

                Assert.That(new List <Ape>()
                {
                    vanya
                },
                            Is.EqualTo(jnki.GetGrandChildren(GenderType.Female, _apeFamilyService)));
            }
Exemple #2
0
        public ApeFamilyService(ApeService apeService)
        {
            _apeService = apeService;

            if (_list == null)
            {
                _list = new List <ApeFamily>();

                ApeFamily family = new ApeFamily("0",
                                                 new List <Ape>()
                {
                    apeService.GetElement("King Shan"), apeService.GetElement("Queen Anga")
                },
                                                 new List <Ape>()
                {
                    apeService.GetElement("Ish"),
                    apeService.GetElement("Chit"),
                    apeService.GetElement("Vich"),
                    apeService.GetElement("Satya")
                });
                ApeFamily family1 = new ApeFamily("1",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Chit"), apeService.GetElement("Ambi")
                },
                                                  new List <Ape>()
                {
                    apeService.GetElement("Drita"),
                    apeService.GetElement("Vrita")
                });
                ApeFamily family2 = new ApeFamily("2",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Vich"), apeService.GetElement("Lika")
                },
                                                  new List <Ape>()
                {
                    apeService.GetElement("Vila"),
                    apeService.GetElement("Chika")
                });

                ApeFamily family3 = new ApeFamily("3",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Satya"), apeService.GetElement("Vyan")
                },
                                                  new List <Ape>()
                {
                    apeService.GetElement("Satvy"),
                    apeService.GetElement("Savya"),
                    apeService.GetElement("Saayan")
                });

                ApeFamily family4 = new ApeFamily("4",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Drita"), apeService.GetElement("Jaya")
                },
                                                  new List <Ape>()
                {
                    apeService.GetElement("Jata"), apeService.GetElement("Driya")
                });

                ApeFamily family5 = new ApeFamily("5",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Driya"), apeService.GetElement("Mnu")
                },
                                                  new List <Ape>()
                {
                });

                ApeFamily family6 = new ApeFamily("6",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Vila"), apeService.GetElement("Jnki")
                },
                                                  new List <Ape>()
                {
                    apeService.GetElement("Lavnya")
                });

                ApeFamily family7 = new ApeFamily("7",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Lavnya"), apeService.GetElement("Gru")
                },
                                                  new List <Ape>()
                {
                });

                ApeFamily family8 = new ApeFamily("8",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Chika"), apeService.GetElement("Kpila")
                },
                                                  new List <Ape>()
                {
                });

                ApeFamily family9 = new ApeFamily("9",
                                                  new List <Ape>()
                {
                    apeService.GetElement("Satvy"), apeService.GetElement("Asva")
                },
                                                  new List <Ape>()
                {
                });

                ApeFamily family10 = new ApeFamily("10",
                                                   new List <Ape>()
                {
                    apeService.GetElement("Savya"), apeService.GetElement("Krpi")
                },
                                                   new List <Ape>()
                {
                    apeService.GetElement("Kriya")
                });

                ApeFamily family11 = new ApeFamily("11",
                                                   new List <Ape>()
                {
                    apeService.GetElement("Saayan"), apeService.GetElement("Mina")
                },
                                                   new List <Ape>()
                {
                    apeService.GetElement("Misa")
                });

                _list.Add(family);
                _list.Add(family1);
                _list.Add(family2);
                _list.Add(family3);
                _list.Add(family4);
                _list.Add(family5);
                _list.Add(family6);
                _list.Add(family7);
                _list.Add(family8);
                _list.Add(family9);
                _list.Add(family10);
                _list.Add(family11);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ApeService                  apeService                  = new ApeService();
            ApeFamilyService            apeFamilyService            = new ApeFamilyService(apeService);
            ApeFamilyAssociationService apeFamilyAssociationService = new ApeFamilyAssociationService(apeFamilyService);

            int userInput = 0;

            do
            {
                userInput = DisplayMenu(apeService);
                switch (userInput)
                {
                case 1:
                    try
                    {
                        Console.WriteLine("Please enter the name of the Ape you want to find relationship for:");
                        string apeName = Console.ReadLine();
                        Console.WriteLine("Enter RelationShip Type");
                        string relationShipType = Console.ReadLine();

                        Ape ape = apeService.GetElement(apeName);

                        Models.RelationshipType relationship;

                        if (!Enum.TryParse(relationShipType, true, out relationship))
                        {
                            throw new Exception("Invalid Relationship");
                        }

                        List <Ape> apes = ape.CalculateRelationship(relationship, apeFamilyAssociationService, apeFamilyService);

                        Utility.PrintName(apes);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("We should start from all over");
                    }

                    break;

                case 2:

                    try
                    {
                        Console.WriteLine("Please enter the name of the parent you want add the family under");
                        string parent = Console.ReadLine();
                        Console.WriteLine("Enter child name:");
                        string child = Console.ReadLine();
                        Console.WriteLine("Enter child gender:");
                        string genderType = Console.ReadLine();

                        Ape parentApe = apeService.GetElement(parent);
                        Models.GenderType gender;
                        if (!Enum.TryParse(genderType, true, out gender))
                        {
                            throw new Exception("We are not aware of such a gender!!");
                        }

                        ApeFamily apeFamily = apeFamilyService.GetAll().SingleOrDefault(p => p.Partners.Contains(parentApe));

                        if (apeFamily == null)
                        {
                            throw new Exception("That would be incorrect. Apes are not Godzillas.");
                        }

                        Ape newBorn = apeFamily.AddNewBorn(child, parentApe.GetDepthLevel() + 1, gender);
                        apeFamilyAssociationService.AddElement(child, apeFamily);
                        apeService.AddElement(newBorn.GetName(), newBorn);

                        Console.WriteLine($"New born {newBorn.GetName()} successfully added to family");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("We should start from all over");
                    }

                    break;

                case 3:

                    Utility.PrintName(apeFamilyService.GetMothersWithMaximumGirlApes());

                    break;

                case 4:

                    try
                    {
                        Console.WriteLine("Please enter the name of the ape1");
                        string ape1Name = Console.ReadLine();
                        Console.WriteLine("Please enter the name of the ape1");
                        string ape2Name = Console.ReadLine();

                        Ape ape1 = apeService.GetElement(ape1Name);
                        Ape ape2 = apeService.GetElement(ape2Name);

                        Utility.PrintName(apeFamilyAssociationService.GetRelationshipBetweenApes(ape1, ape2));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("We should start from all over");
                    }
                    break;
                }
            } while (userInput != 5);

            Console.WriteLine();
        }