예제 #1
0
        public virtual bool Equals(ICollectionValue <T> other)
        {
            // Prepare CopyTo()
            var padding       = 2;
            var expectedArray = new T[Count + 2 * padding];

            CopyTo(expectedArray, padding);
            var actualArray = new T[other.Count + 2 * padding];

            other.CopyTo(actualArray, padding);

            return
                // Properties
                (AllowsNull == other.AllowsNull &&
                 Count == other.Count &&
                 CountSpeed == other.CountSpeed &&
                 IsEmpty == other.IsEmpty

                 // Pure methods
                 && (!HasChoose || Choose().IsSameAs(other.Choose())) &&
                 (_sequenced ? expectedArray.SequenceEqual(actualArray, EqualityComparer) : expectedArray.UnsequenceEqual(actualArray, EqualityComparer)) &&
                 (_sequenced ? this.SequenceEqual(other, EqualityComparer) : this.UnsequenceEqual(other, EqualityComparer))
                 // Show() is tested with ToString()
                 && (_sequenced ? ToArray().SequenceEqual(other.ToArray(), EqualityComparer) : ToArray().UnsequenceEqual(other.ToArray(), EqualityComparer)) &&
                 (!_sequenced || ToString().Equals(other.ToString())));  // TODO: Should they always return the same result? Couldn't this differ between collection types?
        }
예제 #2
0
        public static bool seteq(ICollectionValue <int> me, params int[] that)
        {
            int[] me2 = me.ToArray();

            Array.Sort(me2);

            int i = 0, maxind = that.Length - 1;

            foreach (int item in me2)
            {
                if (i > maxind || item != that[i++])
                {
                    return(false);
                }
            }

            return(i == maxind + 1);
        }
 /// <summary>
 /// Create an array from the items of the wrapped collection
 /// </summary>
 /// <returns>The array</returns>
 public virtual T[] ToArray()
 {
     return(collectionvalue.ToArray());
 }