Example #1
0
        public static FamilyTree GetTree()
        {
            FamilyMember greg   = new FamilyMember("Greg", Gender.Male),
                         pam    = new FamilyMember("Pam", Gender.Female),
                         jeff   = new FamilyMember("Jeff", Gender.Male),
                         brent  = new FamilyMember("Brent", Gender.Male),
                         kyle   = new FamilyMember("Kyle", Gender.Male),
                         jaclyn = new FamilyMember("Jaclyn", Gender.Female),
                         roxi   = new FamilyMember("Roxi", Gender.Female),
                         della  = new FamilyMember("Della", Gender.Female),
                         aura   = new FamilyMember("Aura", Gender.Female);

            var tree = new FamilyTree();

            tree.SetRoot(new Partnership(greg, pam), pam);
            var root = tree.Root;

            tree.AddChild(root, jeff);
            tree.AddChild(root, brent);
            tree.AddChild(root, kyle);
            tree.AddInLaw(jaclyn);
            tree.AddInLaw(aura);

            var brentJaclyn = tree.AddPartnership(brent, jaclyn);

            tree.AddChild(brentJaclyn, roxi);
            tree.AddChild(brentJaclyn, della);

            var jeffAura = tree.AddPartnership(jeff, aura);

            return(tree);
        }
Example #2
0
        private static void ProcessCommand(Command command, string[] parts)
        {
            string result;

            switch (command)
            {
            case Command.ADD_CHILD:
                string mother = parts[1];
                string child  = parts[2];
                Gender gender = GenderToEnum(parts[3]);
                result = familyTree.AddChild(mother, child, gender);
                Console.WriteLine(result);
                break;

            case Command.GET_RELATIONSHIP:
                string   person   = parts[1];
                Relation relation = RelationToEnum(parts[2]);
                result = familyTree.GetRelationship(person, relation);
                Console.WriteLine(result);
                break;
            }
        }
Example #3
0
        public void GivenRootNodesAreSetWhenAddingChildToMotherThenChildWillBeAdded()
        {
            var newNode   = _familyTree.AddChild(FamilyTree.QueenName, ChildName, Gender.Female);
            var queenNode = _familyTree.FindByName(FamilyTree.QueenName);

            Assert.IsNotNull(newNode);
            Assert.AreEqual(newNode.Gender, Gender.Female);
            Assert.AreEqual(newNode.Mother, queenNode);
        }