コード例 #1
0
        public void GetElementsDefensiveCopy(MegaCorp megaCorp, ICapitalist capitalist)
        {
            ISet <ICapitalist> elements = megaCorp.GetElements();

            elements.Add(capitalist);
            Assert.False(megaCorp.Has(capitalist), "#GetElements() returned a live set of elements that allowed external changes to the MegaCorp");
            elements = megaCorp.GetElements();
            Assert.False(megaCorp.Has(capitalist), "#GetElements() returned a live set of elements that allowed external changes to the MegaCorp");
        }
コード例 #2
0
        public void GetElementsEmpty(MegaCorp megaCorp)
        {
            ISet <ICapitalist> elements = megaCorp.GetElements();

            Assert.NotNull(elements);
            Assert.Empty(elements);
        }
コード例 #3
0
        public void GetElementsMultipleArbitraryCapitalists(MegaCorp megaCorp, ISet <ICapitalist> capitalists)
        {
            ISet <ICapitalist> expected = new HashSet <ICapitalist>(capitalists);

            foreach (ICapitalist capitalist in capitalists)
            {
                megaCorp.Add(capitalist);

                ICapitalist parent = capitalist;
                while (parent != null)
                {
                    expected.Add(parent);
                    parent = parent.GetParent();
                }
            }
            ISet <ICapitalist> elements = megaCorp.GetElements();

            Assert.True(expected.SetEquals(elements), "#GetElements() returned a set that did not equal the set of previously-added Capitalists and their parents");
        }
コード例 #4
0
        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");
        }