예제 #1
0
파일: Tester.cs 프로젝트: perl-easj/OOProg
        public void Run()
        {
            #region Creation of Persons
            Person alice  = new Person("Alice", 46, false);
            Person benny  = new Person("Benny", 45, true);
            Person carol  = new Person("Carol", 48, false);
            Person daniel = new Person("Daniel", 51, true);

            Person eric  = new Person("Eric", 17, true);
            Person fiona = new Person("Fiona", 12, false);
            Person gary  = new Person("Gary", 21, true);
            Person harry = new Person("Harry", 15, true);
            Person ian   = new Person("Ian", 10, true);
            Person jacob = new Person("Jacob", 6, true);
            Person karen = new Person("Karen", 9, false);

            Person alicesMom  = new Person("Alice's mom", 78, false);
            Person alicesDad  = new Person("Alice's dad", 80, true);
            Person bennysMom  = new Person("Benny's mom", 75, false);
            Person carolsDad  = new Person("Carol's dad", 83, true);
            Person danielsMom = new Person("Daniel's mom", 81, false);
            Person danielsDad = new Person("Daniel's dad", 85, true);

            Person liam   = new Person("Liam", 44, true);
            Person mary   = new Person("Mary", 38, false);
            Person neil   = new Person("Neil", 52, true);
            Person oscar  = new Person("Oscar", 41, true);
            Person pamela = new Person("Pamela", 29, false);
            Person quincy = new Person("Quincy", 49, true);
            Person robert = new Person("Robert", 56, true);
            Person sandra = new Person("Sandra", 36, false);
            Person tony   = new Person("Tony", 32, true);
            Person ursula = new Person("Ursula", 57, false);
            #endregion


            #region Creation of Relations
            Relation aliceBenny  = new Relation(alice, benny, RelationType.exSpouse);
            Relation carolDaniel = new Relation(carol, daniel, RelationType.exSpouse);
            Relation aliceDaniel = new Relation(alice, daniel, RelationType.spouse);
            Relation carolBenny  = new Relation(carol, benny, RelationType.spouse);

            Relation aliceEric  = new Relation(alice, eric, RelationType.parent);
            Relation aliceFiona = new Relation(alice, fiona, RelationType.parent);
            Relation aliceIan   = new Relation(alice, ian, RelationType.parent);
            Relation aliceJacob = new Relation(alice, jacob, RelationType.parent);

            Relation bennyEric  = new Relation(benny, eric, RelationType.parent);
            Relation bennyFiona = new Relation(benny, fiona, RelationType.parent);
            Relation bennyKaren = new Relation(benny, karen, RelationType.parent);

            Relation carolGary  = new Relation(carol, gary, RelationType.parent);
            Relation carolHarry = new Relation(carol, harry, RelationType.parent);
            Relation carolKaren = new Relation(carol, karen, RelationType.parent);

            Relation danielGary  = new Relation(daniel, gary, RelationType.parent);
            Relation danielHarry = new Relation(daniel, harry, RelationType.parent);
            Relation danielIan   = new Relation(daniel, ian, RelationType.parent);
            Relation danielJacob = new Relation(daniel, jacob, RelationType.parent);

            Relation aliceAliceMom   = new Relation(alice, alicesMom, RelationType.child);
            Relation aliceAliceDad   = new Relation(alice, alicesDad, RelationType.child);
            Relation bennyBennyMom   = new Relation(benny, bennysMom, RelationType.child);
            Relation carolCarolDad   = new Relation(carol, carolsDad, RelationType.child);
            Relation danielDanielMom = new Relation(daniel, danielsMom, RelationType.child);
            Relation danielDanielDad = new Relation(daniel, danielsDad, RelationType.child);

            Relation aliceF1 = new Relation(alice, liam, RelationType.friend);
            Relation aliceF2 = new Relation(alice, mary, RelationType.friend);
            Relation aliceF3 = new Relation(alice, oscar, RelationType.friend);
            Relation aliceF4 = new Relation(alice, sandra, RelationType.friend);
            Relation aliceF5 = new Relation(alice, ursula, RelationType.friend);

            Relation bennyF1 = new Relation(benny, liam, RelationType.friend);
            Relation bennyF2 = new Relation(benny, neil, RelationType.friend);
            Relation bennyF3 = new Relation(benny, robert, RelationType.friend);
            Relation bennyF4 = new Relation(benny, sandra, RelationType.friend);
            Relation bennyF5 = new Relation(benny, ursula, RelationType.friend);

            Relation carolF1 = new Relation(carol, liam, RelationType.friend);
            Relation carolF2 = new Relation(carol, mary, RelationType.friend);
            Relation carolF3 = new Relation(carol, oscar, RelationType.friend);
            Relation carolF4 = new Relation(carol, quincy, RelationType.friend);
            Relation carolF5 = new Relation(carol, tony, RelationType.friend);
            Relation carolF6 = new Relation(carol, ursula, RelationType.friend);

            Relation danielF1 = new Relation(daniel, mary, RelationType.friend);
            Relation danielF2 = new Relation(daniel, neil, RelationType.friend);
            Relation danielF3 = new Relation(daniel, oscar, RelationType.friend);
            Relation danielF4 = new Relation(daniel, pamela, RelationType.friend);
            Relation danielF5 = new Relation(daniel, robert, RelationType.friend);
            Relation danielF6 = new Relation(daniel, ursula, RelationType.friend);
            #endregion


            #region Polulation of collections
            _allPersons = new List <Person>
            {
                alice, benny, carol, daniel, eric, fiona, gary, harry, ian, jacob, karen,
                alicesMom, alicesDad, bennysMom, carolsDad, danielsMom, danielsDad,
                liam, mary, neil, oscar, pamela, quincy, robert, sandra, tony, ursula
            };

            _allRelations = new List <Relation>
            {
                aliceBenny, carolDaniel, aliceDaniel, carolBenny,
                aliceEric, aliceFiona, aliceIan, aliceJacob,
                bennyEric, bennyFiona, bennyKaren,
                carolGary, carolHarry, carolKaren,
                danielGary, danielHarry, danielIan, danielJacob,
                aliceAliceMom, aliceAliceDad, bennyBennyMom, carolCarolDad, danielDanielMom, danielDanielDad,
                aliceF1, aliceF2, aliceF3, aliceF4, aliceF5,
                bennyF1, bennyF2, bennyF3, bennyF4, bennyF5,
                carolF1, carolF2, carolF3, carolF4, carolF5, carolF6,
                danielF1, danielF2, danielF3, danielF4, danielF5, danielF6
            };
            #endregion


            #region Step 1: List of Persons who are common friends for Alice and her spouse
            List <Person> aliceFriends = PersonToPersonsWithRelation(alice, _allRelations, RelationType.friend);

            Person        aliceSpouse        = PersonToPersonsWithRelation(alice, _allRelations, RelationType.spouse).First();
            List <Person> aliceSpouseFriends = PersonToPersonsWithRelation(aliceSpouse, _allRelations, RelationType.friend);

            List <Person> commonFriends = aliceFriends.Intersect(aliceSpouseFriends).ToList();

            PrintPersons("Friends of Alice", aliceFriends);
            PrintPersons("Friends of Alice's spouse", aliceSpouseFriends);
            PrintPersons("Common friends of Alice and Alice's spouse", commonFriends);
            #endregion


            #region Step 2: List of Persons who are friends with either Carol or her spouse (or both)
            List <Person> carolFriends = PersonToPersonsWithRelation(carol, _allRelations, RelationType.friend);

            Person        carolSpouse        = PersonToPersonsWithRelation(carol, _allRelations, RelationType.spouse).First();
            List <Person> carolSpouseFriends = PersonToPersonsWithRelation(carolSpouse, _allRelations, RelationType.friend);

            List <Person> allFriends = carolFriends.Union(carolSpouseFriends).ToList();

            PrintPersons("Friends of Carol", carolFriends);
            PrintPersons("Friends of Carol's spouse", carolSpouseFriends);
            PrintPersons("Friends of Carol or Carol's spouse (or both)", allFriends);
            #endregion


            #region Step 3: Find a secret date for the person not invited
            List <Person> onlyFriends = AllPersonsWithRelation(_allRelations, RelationType.friend)
                                        .Except(AllPersonsWithRelation(_allRelations, RelationType.spouse))
                                        .ToList();

            Person notInvited       = onlyFriends.Except(commonFriends).Except(allFriends).First();
            Person datingNotInvited = PersonToPersonsWithRelation(notInvited, _allRelations, RelationType.friend).First();

            Console.WriteLine($"A secret date was arranged between {notInvited?.Name} and {datingNotInvited?.Name}...");
            Console.WriteLine();
            Console.WriteLine();
            #endregion


            #region Step 4: Print out Family Tree Nodes for all persons
            _allPersons.ForEach(GenerateAndPrintFamilyTreeNode);
            #endregion
        }
예제 #2
0
 private bool SelfIsPersonB(Relation aRelation)
 {
     return(aRelation.PersonB.Name == Self.Name);
 }