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"); }
public void GetHierarchyEmpty(MegaCorp megaCorp) { IDictionary <FatCat, ISet <ICapitalist> > hierarchy = megaCorp.GetHierarchy(); Assert.NotNull(hierarchy); Assert.Empty(hierarchy); }
public void GetHierarchyInitializesChildSets(MegaCorp megaCorp, FatCat fatCat) { megaCorp.Add(fatCat); ISet <ICapitalist> children = megaCorp.GetHierarchy()[fatCat]; Assert.NotNull(children); Assert.Empty(children); }
public void GetHierarchyConsistencyWithOneLevel(MegaCorp megaCorp) { IDictionary <FatCat, ISet <ICapitalist> > hierarchy = megaCorp.GetHierarchy(); ISet <FatCat> expectedParents = megaCorp.GetParents(); Assert.True(expectedParents.SetEquals(hierarchy.Keys), "#GetHierarchy() returned a map with a key set that did not match the MegaCorp's parents"); ISet <ICapitalist> actualElements = new HashSet <ICapitalist>(); foreach (FatCat parent in expectedParents) { actualElements.Add(parent); ISet <ICapitalist> expectedChildren = megaCorp.GetChildren(parent); foreach (ICapitalist capitalist in expectedChildren) { actualElements.Add(capitalist); } Assert.True(expectedChildren.SetEquals(hierarchy[parent]), "#GetHierarchy() returned a map in which a key's associated set of values did not match the MegaCorp's children for that key"); } Assert.True(megaCorp.GetElements().SetEquals(actualElements), "#GetHierarchy() returned a map in which a key's associated set of values did not match the MegaCorp's children for that key"); }