コード例 #1
0
ファイル: Set.cs プロジェクト: Oragon/Oragon.Spring
        /// <summary>
        /// Returns a clone of the <see cref="Oragon.Spring.Collections.ISet"/>
        /// instance.
        /// </summary>
        /// <remarks>
        /// <p>
        /// This will work for derived <see cref="Oragon.Spring.Collections.ISet"/>
        /// classes if the derived class implements a constructor that takes no
        /// arguments.
        /// </p>
        /// </remarks>
        /// <returns>A clone of this object.</returns>
        public virtual object Clone()
        {
            Set newSet = (Set)Activator.CreateInstance(this.GetType());

            newSet.AddAll(this);
            return(newSet);
        }
コード例 #2
0
 public void RetainAll()
 {
     Set.AddAll(UniqueStuff);
     Set.RetainAll(new object [] { StuffOne, StuffTwo });
     Assert.IsTrue(Set.Count == 2);
     Assert.IsTrue(Set.Contains(StuffOne));
     Assert.IsTrue(Set.Contains(StuffTwo));
     Assert.IsFalse(Set.Contains(StuffThree));
 }
コード例 #3
0
 public void Remove()
 {
     Set.AddAll(UniqueStuff);
     Set.Remove(StuffOne);
     Assert.IsTrue(Set.Count == (UniqueStuff.Length - 1));
     Assert.IsFalse(Set.Contains(StuffOne));
     Assert.IsTrue(Set.Contains(StuffTwo));
     Assert.IsTrue(Set.Contains(StuffThree));
 }
コード例 #4
0
 public void RemoveAll()
 {
     Set.AddAll(UniqueStuff);
     object [] removed = new object [] { StuffOne, StuffTwo };
     Set.RemoveAll(removed);
     Assert.IsTrue(Set.Count == (UniqueStuff.Length - removed.Length));
     Assert.IsFalse(Set.Contains(StuffOne));
     Assert.IsFalse(Set.Contains(StuffTwo));
     Assert.IsTrue(Set.Contains(StuffThree));
 }
コード例 #5
0
 public void RemoveNull()
 {
     if (SupportsNull)
     {
         Set.AddAll(UniqueStuff);
         Assert.IsFalse(Set.Remove(null));
         Set.Add(null);
         Assert.IsTrue(Set.Remove(null));
     }
 }
コード例 #6
0
        public void Minus()
        {
            Set.AddAll(UniqueStuff);
            SetForSetOps.AddAll(new object [] { "Bar", StuffOne });
            ISet minus = Set.Minus(SetForSetOps);

            Assert.IsTrue(minus.Count == UniqueStuff.Length - 1);
            Assert.IsFalse(object.ReferenceEquals(minus, Set), "Got back same instance after set operation.");
            Assert.IsTrue(Set.Count == UniqueStuff.Length);
            Assert.IsTrue(SetForSetOps.Count == 2);
        }
コード例 #7
0
        public void Intersect()
        {
            Set.AddAll(UniqueStuff);
            SetForSetOps.AddAll(new object [] { "Bar", StuffOne });
            ISet intersection = Set.Intersect(SetForSetOps);

            Assert.IsTrue(intersection.Count == 1);
            Assert.IsFalse(object.ReferenceEquals(intersection, Set), "Got back same instance after set operation.");
            Assert.IsTrue(Set.Count == UniqueStuff.Length);
            Assert.IsTrue(SetForSetOps.Count == 2);
        }
コード例 #8
0
        public void ExclusiveOr()
        {
            Set.AddAll(UniqueStuff);
            SetForSetOps.AddAll(new object [] { "Bar", StuffOne });
            ISet xor = Set.ExclusiveOr(SetForSetOps);

            Assert.IsTrue(xor.Count == 3);
            Assert.IsTrue(xor.ContainsAll(new object [] { "Bar", StuffTwo, StuffThree }));
            Assert.IsFalse(object.ReferenceEquals(xor, Set), "Got back same instance after set operation.");
            Assert.IsTrue(Set.Count == UniqueStuff.Length);
            Assert.IsTrue(SetForSetOps.Count == 2);
        }
コード例 #9
0
 public void EnumeratesNull()
 {
     if (SupportsNull)
     {
         Set.AddAll(new object [] { StuffOne, null, StuffTwo });
         bool gotNull = false;
         foreach (object o in Set)
         {
             if (o == null)
             {
                 gotNull = true;
                 break;
             }
         }
         Assert.IsTrue(gotNull, "Stuffed a null value into the set but didn't get it back when enumerating over the set.");
     }
 }
コード例 #10
0
 public void CopiesNull()
 {
     if (SupportsNull)
     {
         object [] expected = new object [] { StuffOne, null, StuffTwo };
         Set.AddAll(expected);
         object [] actual = new object [expected.Length];
         Set.CopyTo(actual, 0);
         bool gotNull = false;
         foreach (object o in actual)
         {
             if (o == null)
             {
                 gotNull = true;
                 break;
             }
         }
         Assert.IsTrue(gotNull, "Copied a set with a null value into an array, but the resulting array did not contain a a null.");
     }
 }
コード例 #11
0
 public void Clear()
 {
     Set.AddAll(UniqueStuff);
     Set.Clear();
     Assert.IsTrue(Set.Count == 0, "Calling Clear () did not remove all of the elements.");
 }
コード例 #12
0
 public void AddAllDuplicated()
 {
     Assert.IsTrue(Set.AddAll(DuplicatedStuff));
     Assert.IsTrue(Set.Count == 2, "Added 3 (2 duplicated) items, but the Count property wasn't sitting at 2.");
 }
コード例 #13
0
 public void AddAll()
 {
     Assert.IsTrue(Set.AddAll(UniqueStuff));
     Assert.IsTrue(Set.Count == UniqueStuff.Length, "Added 3 unique items, but the Count property wasn't sitting at 3.");
 }
コード例 #14
0
 public void ContainsAll()
 {
     Set.AddAll(UniqueStuff);
     Assert.IsTrue(Set.ContainsAll(new object [] { StuffThree, StuffTwo, StuffOne }));
 }
コード例 #15
0
 public void Contains()
 {
     Set.AddAll(UniqueStuff);
     Assert.IsTrue(Set.Contains(StuffThree));
     Assert.IsFalse(Set.Contains("SourDough"));
 }
コード例 #16
0
 public void AddAll()
 {
     Assert.Throws <NotSupportedException>(() => Set.AddAll(new int[] { 4, 5, 6 }));
 }