public void GetHierarchyDefensiveCopy(MegaCorp megaCorp, WageSlave wageSlave)
        {
            ISet <ICapitalist> children = new HashSet <ICapitalist>();

            children.Add(wageSlave);
            IDictionary <FatCat, ISet <ICapitalist> > hierarchy = megaCorp.GetHierarchy();

            hierarchy.Add(wageSlave.GetParent(), children);
            Assert.False(megaCorp.Has(wageSlave.GetParent()), "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");
            Assert.False(megaCorp.Has(wageSlave), "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");

            hierarchy = megaCorp.GetHierarchy();

            Assert.False(children.SetEquals(hierarchy.ContainsKey(wageSlave.GetParent()) ? hierarchy[wageSlave.GetParent()] : new HashSet <ICapitalist>()),
                         "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");
            Assert.False(hierarchy.ContainsKey(wageSlave.GetParent()), "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");

            megaCorp.Add(wageSlave.GetParent());
            hierarchy = megaCorp.GetHierarchy();
            children  = hierarchy[wageSlave.GetParent()];
            children.Add(wageSlave);
            Assert.False(megaCorp.Has(wageSlave), "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");

            hierarchy = megaCorp.GetHierarchy();
            Assert.False(hierarchy[wageSlave.GetParent()].Contains(wageSlave), "#getHierarchy() returned a live map that allowed external changes to the MegaCorp");
        }
        static void Main(string[] args)
        {
            MegaCorp  megaCorp = new MegaCorp();
            FatCat    Madea    = new FatCat("Madea", 26000);
            FatCat    Marie    = new FatCat("Marie", 26000);
            FatCat    LucasSr  = new FatCat("LucasSr", 26000, Marie);
            FatCat    Miriam   = new FatCat("Miriam", 26000, Marie);
            FatCat    Katie    = new FatCat("Katie", 26000, Madea);
            FatCat    Zack     = new FatCat("Zack", 26000, Madea);
            WageSlave Lucas    = new WageSlave("Lucas", 26000, LucasSr);
            WageSlave Marcus   = new WageSlave("Marcus", 26000, Katie);
            WageSlave Markel   = new WageSlave("Markel", 26000, Katie);
            WageSlave Ashley   = new WageSlave("Ashley", 26000, Miriam);

            megaCorp.Add(Madea);
            megaCorp.Add(Marie);
            megaCorp.Add(LucasSr);
            megaCorp.Add(Miriam);
            megaCorp.Add(Katie);
            megaCorp.Add(Zack);
            megaCorp.Add(Lucas);
            megaCorp.Add(Marcus);
            megaCorp.Add(Markel);
            megaCorp.Add(Ashley);

            IEnumerable <string> query = from item in megaCorp.GetElements() select item.GetName();

            foreach (var n in query)
            {
                Console.WriteLine(n);
            }
        }
Example #3
0
        public void FullValueEquality(string name, int salary, FatCat parent)
        {
            WageSlave firstCopy  = new WageSlave(name, salary, parent);
            WageSlave secondCopy = new WageSlave(name, salary, parent);

            Assert.Equal(firstCopy, secondCopy);
        }
Example #4
0
        public void NoOwnerValueEquality(string name, int salary)
        {
            WageSlave firstCopy  = new WageSlave(name, salary);
            WageSlave secondCopy = new WageSlave(name, salary);

            Assert.Equal(firstCopy, secondCopy);
        }
Example #5
0
        public void FullConstructor(string name, int salary, FatCat parent)
        {
            WageSlave wageSlave = new WageSlave(name, salary, parent);

            Assert.Equal(name, wageSlave.GetName());
            Assert.Equal(salary, wageSlave.GetSalary());
            Assert.Equal(parent, wageSlave.GetParent());
            Assert.True(wageSlave.HasParent(), "HasParent() did not return true when constructed with an owner");
        }
Example #6
0
        public void NoOwnerConstructor(string name, int salary)
        {
            WageSlave wageSlave = new WageSlave(name, salary);

            Assert.Equal(name, wageSlave.GetName());
            Assert.Equal(salary, wageSlave.GetSalary());
            Assert.Null(wageSlave.GetParent());
            Assert.False(wageSlave.HasParent(), "HasParent() did not return false when constructed without an owner");
        }
        public void GetParentsWageSlaveWithParent(MegaCorp megaCorp, WageSlave wageSlave)
        {
            megaCorp.Add(wageSlave);
            FatCat        parent  = wageSlave.GetParent();
            ISet <FatCat> parents = megaCorp.GetParents();

            Assert.NotEmpty(parents);
            Assert.Equal(1, parents.Count);
            Assert.True(parents.Contains(parent), "#getParents() returned a set that did not contain the parent of the WageSlave added to the MegaCorp");
        }
 public void AddHasParentlessWageSlave(MegaCorp megaCorp, WageSlave wageSlave)
 {
     Assert.False(megaCorp.Add(wageSlave), "#Add() returned true when called with a parent-less WageSlave");
     Assert.False(megaCorp.Has(wageSlave), "#Has() returned true when called with a parent-less WageSlave that failed to be added");
 }