Exemplo n.º 1
0
        public void GetSet_TypicalCase()
        {
            var elements = new int[] { 1, 2, 3, 4, 5 };
            var sets     = new DisjointSets <int>(elements);

            foreach (int element in elements)
            {
                Assert.That(sets.GetSet(element), Is.EquivalentTo(new SortedSet <int>(new int[] { element })));
            }
        }
Exemplo n.º 2
0
        public void GetSet_TypicalCase2()
        {
            var sets = new DisjointSets <int>(new int[] { 1, 2, 3, 4, 5, 6 });

            sets.Union(1, 2);
            sets.Union(1, 6);
            sets.Union(3, 4);

            Assert.That(sets.GetSet(1), Is.EquivalentTo(new HashSet <int>(new int[] { 1, 2, 6 })));
            Assert.That(sets.GetSet(2), Is.EquivalentTo(new HashSet <int>(new int[] { 1, 2, 6 })));
            Assert.That(sets.GetSet(6), Is.EquivalentTo(new HashSet <int>(new int[] { 1, 2, 6 })));
            Assert.That(sets.GetSet(3), Is.EquivalentTo(new HashSet <int>(new int[] { 3, 4 })));
            Assert.That(sets.GetSet(4), Is.EquivalentTo(new HashSet <int>(new int[] { 3, 4 })));
            Assert.That(sets.GetSet(5), Is.EquivalentTo(new HashSet <int>(new int[] { 5 })));
        }
Exemplo n.º 3
0
        public void GetSet_ThrowsOnNonExistentElement()
        {
            var sets = new DisjointSets <int>(new int[] { 1, 2 });

            Assert.That(() => sets.GetSet(3), Throws.ArgumentException);
        }