public void TestSymmetricExcept()
        {
            IImmutableSet <int> set    = CreateSet <int>();
            IImmutableSet <int> second = CreateSet <int>();

            Assert.Throws <ArgumentNullException>(() => set.SymmetricExcept(null));

            // Test behavior when the current set is empty
            set    = set.SymmetricExcept(TransformEnumerableForSetOperation(new[] { 1, 5, 3 }));
            second = second.Union(TransformEnumerableForSetOperation(new[] { 1, 5, 3 }));
            Assert.Equal(second.ToArray(), set);

            // Test SymmetricExceptWith self
            Assert.NotEmpty(set);
            set = set.SymmetricExcept(TransformEnumerableForSetOperation(set));
            Assert.Empty(set);
            set = set.SymmetricExcept(TransformEnumerableForSetOperation(set));
            Assert.Empty(set);

            // Test SymmetricExceptWith same set type
            IImmutableSet <int> other = CreateSet <int>();

            set   = set.Union(TransformEnumerableForSetOperation(new[] { 1, 3, 5 }));
            other = other.Union(TransformEnumerableForSetOperation(new[] { 3, 5, 7 }));
            set   = set.SymmetricExcept(TransformEnumerableForSetOperation(other));
            Assert.Equal(new[] { 1, 7 }, set);

            // Test SymmetricExceptWith same set type
            set   = set.Clear();
            other = CreateSet <int>();
            set   = set.Union(TransformEnumerableForSetOperation(new[] { 1, 3, 5 }));
            other = other.Union(TransformEnumerableForSetOperation(new[] { 3, 5, 7 }));
            set   = set.SymmetricExcept(TransformEnumerableForSetOperation(other.ToArray()));
            Assert.Equal(new[] { 1, 7 }, set);
        }
        public void TestIsSupersetOf()
        {
            IImmutableSet <int> set = CreateSet <int>();

            Assert.Throws <ArgumentNullException>(() => set.IsSupersetOf(null));

            // Test IsSupersetOf self
            set = set.Add(1);
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(set)));
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(set.ToArray())));

            // Test IsSupersetOf empty
            Assert.NotEmpty(set);
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(new int[0])));

            // Test IsSupersetOf array
            set = set.Union(TransformEnumerableForSetOperation(Enumerable.Range(0, 10)));
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 5, 7, 9 })));
            Assert.False(set.IsSupersetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 11, 5, 7, 9 })));
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(Enumerable.Range(0, 10))));

            // Test IsSupersetOf same set type
            set = set.Clear();
            set = set.Union(TransformEnumerableForSetOperation(Enumerable.Range(3, 5)));
            IImmutableSet <int> other = CreateSet <int>();

            other = other.Union(TransformEnumerableForSetOperation(new[] { 3, 5 }));
            Assert.True(set.IsSupersetOf(TransformEnumerableForSetOperation(other)));
            Assert.False(other.IsSupersetOf(TransformEnumerableForSetOperation(set)));

            other = other.Remove(5);
            other = other.Add(8);
            Assert.True(set.Count > other.Count);
            Assert.False(set.IsSupersetOf(TransformEnumerableForSetOperation(other)));
        }
        public void TestIsSubsetOf()
        {
            IImmutableSet <int> set = CreateSet <int>();

            Assert.Throws <ArgumentNullException>(() => set.IsSubsetOf(null));

            // Return without iterating if the set is already empty
            Assert.True(set.IsSubsetOf(EverythingThrowsEnumerable <int> .Instance));

            // Test IsSubsetOf self
            set = set.Add(1);
            Assert.True(set.IsSubsetOf(TransformEnumerableForSetOperation(set)));
            Assert.True(set.IsSubsetOf(TransformEnumerableForSetOperation(set.ToArray())));

            // Test IsSubsetOf array
            set = set.Union(TransformEnumerableForSetOperation(new[] { 3, 5, 7 }));
            Assert.True(set.IsSubsetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 5, 7, 9 })));
            Assert.False(set.IsSubsetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 7, 9 })));
            Assert.True(set.IsSubsetOf(TransformEnumerableForSetOperation(Enumerable.Range(0, 10))));

            // Test IsSubsetOf same set type
            set = set.Clear();
            set = set.Union(TransformEnumerableForSetOperation(new[] { 3, 5 }));
            IImmutableSet <int> other = CreateSet <int>();

            other = other.Union(TransformEnumerableForSetOperation(Enumerable.Range(3, 5)));
            Assert.True(set.IsSubsetOf(TransformEnumerableForSetOperation(other)));
            Assert.False(other.IsSubsetOf(TransformEnumerableForSetOperation(set)));

            set = set.Remove(5);
            set = set.Add(8);
            Assert.True(set.Count < other.Count);
            Assert.False(set.IsSubsetOf(TransformEnumerableForSetOperation(other)));
        }
        public void TestIsProperSubsetOf()
        {
            IImmutableSet <int> set = CreateSet <int>();

            Assert.Throws <ArgumentNullException>(() => set.IsProperSubsetOf(null));

            // Test behavior when the current set is empty
            Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(Enumerable.Empty <int>())));
            Assert.True(set.IsProperSubsetOf(TransformEnumerableForSetOperation(Enumerable.Range(0, 1))));

            // Test IsProperSubsetOf self
            set = set.Add(1);
            Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(set)));
            Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(set.ToArray())));

            // Test IsProperSubsetOf array
            set = set.Union(new[] { 3, 5, 7 });
            Assert.True(set.IsProperSubsetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 5, 7, 9 })));
            Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(new[] { 1, 3, 7, 9 })));
            Assert.True(set.IsProperSubsetOf(TransformEnumerableForSetOperation(Enumerable.Range(0, 10))));

            // Test IsProperSubsetOf same set type
            set = set.Clear();
            set = set.Union(TransformEnumerableForSetOperation(new[] { 3, 5 }));
            IImmutableSet <int> other = CreateSet <int>();

            other = other.Union(TransformEnumerableForSetOperation(Enumerable.Range(3, 5)));
            Assert.True(set.IsProperSubsetOf(TransformEnumerableForSetOperation(other)));
            Assert.False(other.IsProperSubsetOf(TransformEnumerableForSetOperation(set)));

            set = set.Remove(5);
            set = set.Add(8);
            Assert.True(set.Count < other.Count);
            Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(other)));
        }
示例#5
0
        /// <summary>
        /// Tests various aspects of a set.  This should be called only from the unordered or sorted overloads of this method.
        /// </summary>
        /// <typeparam name="T">The type of element stored in the set.</typeparam>
        /// <param name="emptySet">The empty set.</param>
        protected void EmptyTestHelper <T>(IImmutableSet <T> emptySet)
        {
            Contract.Requires(emptySet != null);

            Assert.Equal(0, emptySet.Count);   //, "Empty set should have a Count of 0");
            Assert.Equal(0, emptySet.Count()); //, "Enumeration of an empty set yielded elements.");
            Assert.Same(emptySet, emptySet.Clear());
        }
        public void TestSetEquals()
        {
            IImmutableSet <int> set = CreateSet <int>();

            Assert.Throws <ArgumentNullException>(() => set.SetEquals(null));

            // Test behavior when the current set is empty
            Assert.True(set.SetEquals(TransformEnumerableForSetOperation(Enumerable.Empty <int>())));
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(Enumerable.Range(0, 1))));

            // Test SetEquals self
            Assert.True(set.SetEquals(TransformEnumerableForSetOperation(set)));

            // Test with same set type
            set = set.Union(TransformEnumerableForSetOperation(Enumerable.Range(0, 10)));
            IImmutableSet <int> other = CreateSet <int>();

            other = other.Union(TransformEnumerableForSetOperation(Enumerable.Range(0, 10)));
            Assert.True(set.SetEquals(TransformEnumerableForSetOperation(other)));

            other = other.Remove(0);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other)));
            other = other.Add(-1);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other)));
            other = other.Remove(-1);
            other = other.Add(0);
            other = other.Remove(8);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other)));
            other = other.Add(11);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other)));

            // Test with different set type
            set   = set.Clear();
            other = other.Clear();
            set   = set.Union(TransformEnumerableForSetOperation(Enumerable.Range(0, 10)));
            other = other.Union(TransformEnumerableForSetOperation(Enumerable.Range(0, 10)));
            Assert.True(set.SetEquals(TransformEnumerableForSetOperation(other.ToArray())));
            Assert.True(set.SetEquals(TransformEnumerableForSetOperation(other.Concat(other).ToArray())));

            other = other.Remove(0);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other.ToArray())));
            other = other.Add(-1);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other.ToArray())));
            other = other.Remove(-1);
            other = other.Add(0);
            other = other.Remove(8);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other.ToArray())));
            other = other.Add(11);
            Assert.False(set.SetEquals(TransformEnumerableForSetOperation(other.ToArray())));
        }
示例#7
0
        protected void TryGetValueTestHelper(IImmutableSet <string> set)
        {
            Requires.NotNull(set, "set");

            string expected = "egg";

            set = set.Add(expected);
            string actual;
            string lookupValue = expected.ToUpperInvariant();

            Assert.True(set.TryGetValue(lookupValue, out actual));
            Assert.Same(expected, actual);

            Assert.False(set.TryGetValue("foo", out actual));
            Assert.Equal("foo", actual);

            Assert.False(set.Clear().TryGetValue("nonexistent", out actual));
            Assert.Equal("nonexistent", actual);
        }
示例#8
0
 public ElementSet Clear()
 {
     return(new ElementSet(_immutableSetImplementation.Clear()));
 }
示例#9
0
 public IImmutableSet <T> Clear() =>
 _set.Clear().ToStructural(0);
 protected override IImmutableSet <T> Clear(IImmutableSet <T> values, ISerializationContext context)
 => values.Clear();