Ejemplo n.º 1
0
 public VectorReadStream(HugeList<byte> vector, int start, int length)
 {
     if (unchecked((uint)start > (uint)vector.Count) || unchecked((uint)start + (uint)length > (uint)vector.Count))
     {
         Debug.Assert(false);
         throw new ArgumentOutOfRangeException();
     }
     this.vector = vector;
     this.start = start;
     this.length = length;
 }
Ejemplo n.º 2
0
        private void InsertRangeHugeListAction(IHugeList <int>[] lists, Random rnd, ref string description)
        {
            IHugeList <int> reference = lists[0];
            int             extent    = reference.Count;

            int insertAt = rnd.Next() % (extent + 1);

            int chunkSize = rnd.Next() % 20 + 1;
            int length    = rnd.Next() % 50;
            int offset    = length > 0 ? rnd.Next() % length : 0;
            int count     = length - offset > 0 ? rnd.Next() % (length - offset) : 0;

            HugeList <int> toAdd            = new HugeList <int>(chunkSize);
            List <int>     insertionIndices = new List <int>();

            for (int i = 0; i < length; i++)
            {
                int index = rnd.Next() % (toAdd.Count + 1); // ensure segment lengths come out randomized
                insertionIndices.Add(index);
                toAdd.Insert(index, rnd.Next());
            }

            bool valid = true;

            if (rnd.Next() % 10 == 0)
            {
                valid = false;
                switch (rnd.Next() % 6)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case 0:
                    count = length + 1;
                    break;

                case 1:
                    count = -1;
                    break;

                case 2:
                    offset = -1;
                    break;

                case 3:
                    insertAt = -1;
                    break;

                case 4:
                    insertAt = extent + 1;
                    break;

                case 5:
                    toAdd = null;
                    break;
                }
            }

            description = String.Format("InsertHugeList ({0}) ({1}, [{2}, {3}, {4}])", valid ? "valid" : "invalid", insertAt, length, offset, count);
            script.AppendLine(String.Format("new OpInsertHugeList<T>({0}, {1}, {2}, {3}, {4}, new int[{6}] {{ {5} }})", chunkSize, length, insertAt, offset, count, String.Join(", ", insertionIndices), insertionIndices.Count));

            for (int i = 0; i < lists.Length; i++)
            {
                try
                {
                    lists[i].InsertRange(insertAt, toAdd, offset, count);
                }
                catch (ArgumentNullException) when(!valid)
                {
                    // expected
                }
                catch (ArgumentOutOfRangeException) when(!valid)
                {
                    // expected
                }
                catch (ArgumentException) when(!valid)
                {
                    // expected
                }
                catch (Exception exception)
                {
                    Fault(lists[i], description + " - threw exception", exception);
                }
            }
        }