Example #1
0
        public void CleanRedundantDependencies_SingleRedundancy_RedundanciesCleared()
        {
            var          rng              = new Random();
            const string innerDependency  = "mostUsedDependency";
            const string outterDependency = "redundant";
            var          entries          = new List <TestSortable>
            {
                new TestSortable(innerDependency),
                new TestSortable(outterDependency, innerDependency),
                new TestSortable("commonEntry1", innerDependency),
                new TestSortable("commonEntry2", innerDependency, outterDependency),
                new TestSortable("commonEntry3", innerDependency, outterDependency),
                new TestSortable("commonEntry4"),
                new TestSortable("commonEntry5", innerDependency, outterDependency),
                new TestSortable("commonEntry6", innerDependency, outterDependency),
                new TestSortable("commonEntry7", innerDependency),
            };
            int originalCount = entries.Count;
            var tree          = new SortedTree <string, TestSortable>();

            // Add entries in random order
            while (entries.Count > 0)
            {
                int rngSelected = rng.Next(0, entries.Count);
                Assert.IsTrue(tree.AddSorted(entries[rngSelected]));
                entries.RemoveAt(rngSelected);
            }

            Assert.AreEqual(originalCount, tree.Count);

            tree.CleanRedundantDependencies();

            Assert.AreEqual(originalCount, tree.Count);
            Assert.AreEqual(4, tree.DependencyUsedBy(outterDependency));
            Assert.AreEqual(3, tree.DependencyUsedBy(innerDependency));

            Assert.IsTrue(tree[outterDependency].Dependencies.Contains(innerDependency));

            Assert.IsTrue(tree["commonEntry1"].Dependencies.Contains(innerDependency));
            Assert.IsTrue(tree["commonEntry2"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry3"].Dependencies.Contains(outterDependency));

            Assert.IsTrue(tree["commonEntry5"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry6"].Dependencies.Contains(outterDependency));
            Assert.IsTrue(tree["commonEntry7"].Dependencies.Contains(innerDependency));

            Assert.IsFalse(tree["commonEntry2"].Dependencies.Contains(innerDependency));
            Assert.IsFalse(tree["commonEntry3"].Dependencies.Contains(innerDependency));

            Assert.IsFalse(tree["commonEntry5"].Dependencies.Contains(innerDependency));
            Assert.IsFalse(tree["commonEntry6"].Dependencies.Contains(innerDependency));
        }