Exemplo n.º 1
0
        public void Contains_Call_LetterSimpleSet_Contains()
        {
            var PolyMorphSet = new HybridSet <string>();

            PolyMorphSet.Contains("key");
            _LetterSimpleSetSubstitute.Received(1).Contains("key");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a value for the arithmetic addition operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            var lhs = GetLeftValue(context, evalContext);
            var rhs = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(lhs) && NumberUtils.IsNumber(rhs))
            {
                return(NumberUtils.Add(lhs, rhs));
            }
            if (lhs is DateTime && (rhs is TimeSpan || rhs is string || NumberUtils.IsNumber(rhs)))
            {
                if (NumberUtils.IsNumber(rhs))
                {
                    rhs = TimeSpan.FromDays(Convert.ToDouble(rhs));
                }
                else if (rhs is string)
                {
                    rhs = TimeSpan.Parse((string)rhs);
                }

                return((DateTime)lhs + (TimeSpan)rhs);
            }
            if (lhs is String || rhs is String)
            {
                return(string.Concat(lhs, rhs));
            }
            if ((lhs is IList || lhs is ISet) && (rhs is IList || rhs is ISet))
            {
                ISet leftset  = new HybridSet(lhs as ICollection);
                ISet rightset = new HybridSet(rhs as ICollection);
                return(leftset.Union(rightset));
            }
            if (lhs is IDictionary && rhs is IDictionary)
            {
                ISet leftset  = new HybridSet(((IDictionary)lhs).Keys);
                ISet rightset = new HybridSet(((IDictionary)rhs).Keys);
                var  unionset = leftset.Union(rightset);

                IDictionary result = new Hashtable(unionset.Count);
                foreach (var key in unionset)
                {
                    if (leftset.Contains(key))
                    {
                        result.Add(key, ((IDictionary)lhs)[key]);
                    }
                    else
                    {
                        result.Add(key, ((IDictionary)rhs)[key]);
                    }
                }
                return(result);
            }
            throw new ArgumentException("Cannot add instances of '"
                                        + lhs.GetType().FullName
                                        + "' and '"
                                        + rhs.GetType().FullName
                                        + "'.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retains only the elements in this set that are contained in the specified collection.
        /// </summary>
        /// <param name="c">Collection that defines the set of elements to be retained.</param>
        /// <returns><c>true</c> if this set changed as a result of this operation.</returns>
        public override bool RetainAll(ICollection c)
        {
            //Put data from C into a set so we can use the Contains() method.
            Set cSet = new HybridSet(c);

            //We are going to build a set of elements to remove.
            Set removeSet = new HybridSet();

            foreach(object o in this)
            {
                //If C does not contain O, then we need to remove O from our
                //set.  We can't do this while iterating through our set, so
                //we put it into RemoveSet for later.
                if(!cSet.Contains(o))
                    removeSet.Add(o);
            }

            return this.RemoveAll(removeSet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a value for the arithmetic addition operator node.
        /// </summary>
        /// <param name="context">Context to evaluate expressions against.</param>
        /// <param name="evalContext">Current expression evaluation context.</param>
        /// <returns>Node's value.</returns>
        protected override object Get(object context, EvaluationContext evalContext)
        {
            object left = GetLeftValue(context, evalContext);
            object right = GetRightValue(context, evalContext);

            if (NumberUtils.IsNumber(left) && NumberUtils.IsNumber(right))
            {
                return NumberUtils.Add(left, right);
            }
            else if (left is DateTime && (right is TimeSpan || right is string || NumberUtils.IsNumber(right)))
            {
                if (NumberUtils.IsNumber(right))
                {
                    right = TimeSpan.FromDays(Convert.ToDouble(right));
                }
                else if (right is string)
                {
                    right = TimeSpan.Parse((string) right);
                }

                return (DateTime) left + (TimeSpan) right;
            }
            else if (left is String || right is String)
            {
                return string.Concat(left, right);
            }
            else if ((left is IList || left is ISet) && (right is IList || right is ISet))
            {
                ISet leftset = new HybridSet(left as ICollection);
                ISet rightset = new HybridSet(right as ICollection);
                return leftset.Union(rightset);
            }
            else if (left is IDictionary && right is IDictionary)
            {
                ISet leftset = new HybridSet(((IDictionary) left).Keys);
                ISet rightset = new HybridSet(((IDictionary) right).Keys);
                ISet unionset = leftset.Union(rightset);
                
                IDictionary result = new Hashtable(unionset.Count);
                foreach(object key in unionset)
                {
                    if(leftset.Contains(key))
                    {
                        result.Add(key, ((IDictionary)left)[key]);
                    }
                    else
                    {
                        result.Add(key, ((IDictionary)right)[key]);
                    }
                }
                return result;
            }
            else
            {
                throw new ArgumentException("Cannot add instances of '"
                                            + left.GetType().FullName
                                            + "' and '"
                                            + right.GetType().FullName
                                            + "'.");
            }
        }