示例#1
0
        private void RemoveAllAction(IHugeList <int>[] lists, Random rnd, ref string description)
        {
            IHugeList <int> reference = lists[0];
            int             extent    = reference.Count;

            int modulus, item;

            switch ((int)(4 * Math.Pow(rnd.NextDouble(), 10))) // reaches '3' in just under 3% of cases
            {
            default:
                Debug.Assert(false);
                throw new InvalidOperationException();

            case 0:     // remove exact item
                if (extent == 0)
                {
                    return;
                }
                modulus = 0;
                item    = reference[rnd.Next() % extent];
                break;

            case 1:     // remove non-match
                modulus = 0;
                do
                {
                    item = rnd.Next();
                } while ((extent != 0) && reference.Contains(item));
                break;

            case 2:     // remove sparse pattern
                modulus = rnd.Next() % 100 + 100;
                item    = 0;
                break;

            case 3:     // remove dense pattern
                modulus = rnd.Next() % 20 + 1;
                item    = 0;
                break;
            }

            string delegateText = String.Format("delegate (int candidate) {{ return ({1} == 0) ? (candidate == {0}) : (candidate % {1} == {0}); }}", item, modulus);

            description = String.Format("RemoveAll [{0}]", delegateText);
            script.AppendLine(String.Format("new OpRemoveAll<T>({0}),", delegateText));
            for (int i = 0; i < lists.Length; i++)
            {
                try
                {
                    lists[i].RemoveAll(delegate(int candidate) { return((modulus == 0) ? (candidate == item) : (candidate % modulus == item)); });
                }
                catch (Exception exception)
                {
                    Fault(lists[i], description + " - threw exception", exception);
                }
            }
        }
示例#2
0
        private void ContainsAction(IHugeList <int>[] lists, Random rnd, ref string description)
        {
            IHugeList <int> reference = lists[0];

            if ((rnd.Next(2) == 0) && (reference.Count != 0))
            {
                // existing
                int item = reference[rnd.Next(reference.Count)];
                description = String.Format("Contains (existing) [{0}]", item);
                for (int i = 0; i < lists.Length; i++)
                {
                    try
                    {
                        bool f = lists[i].Contains(item);
                        if (!f)
                        {
                            Fault(lists[i], description + " - returned false");
                        }
                    }
                    catch (Exception exception)
                    {
                        Fault(lists[i], description + " - threw exception", exception);
                    }
                }
            }
            else
            {
                // missing
                int item;
                do
                {
                    item = rnd.Next(Int32.MinValue, Int32.MaxValue);
                }while (reference.Contains(item));
                description = String.Format("Contains (missing) [{0}]", item);
                for (int i = 0; i < lists.Length; i++)
                {
                    try
                    {
                        bool f = lists[i].Contains(item);
                        if (f)
                        {
                            Fault(lists[i], description + " - returned true");
                        }
                    }
                    catch (Exception exception)
                    {
                        Fault(lists[i], description + " - threw exception", exception);
                    }
                }
            }
        }