Exemplo n.º 1
0
        public void CopyTo_Empty_NothingCopied()
        {
            IProducerConsumerCollection <int> c = CreateProducerConsumerCollection();

            c.CopyTo(new int[0], 0);
            c.CopyTo(new int[10], 10);
        }
Exemplo n.º 2
0
        public void CopyTo_InvalidArgs_Throws()
        {
            IProducerConsumerCollection <int> c = CreateProducerConsumerCollection(Enumerable.Range(0, 10));

            int[] dest = new int[10];

            Assert.Throws <ArgumentNullException>("array", () => c.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(dest, -1));
            Assert.Throws <ArgumentException>(() => c.CopyTo(dest, dest.Length));
            Assert.Throws <ArgumentException>(() => c.CopyTo(dest, dest.Length - 2));
        }
Exemplo n.º 3
0
        public void CopyTo_SzArray_NonZeroIndex_ExpectedElementsCopied(int size)
        {
            IEnumerable <int> initialItems = Enumerable.Range(1, size);

            IProducerConsumerCollection <int> c = CreateProducerConsumerCollection(initialItems);

            int[] actual = new int[size + 2];
            c.CopyTo(actual, 1);

            IProducerConsumerCollection <int> oracle = CreateOracle(initialItems);

            int[] expected = new int[size + 2];
            oracle.CopyTo(expected, 1);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
 void ICollection.CopyTo(Array array, int index)
 {
     underlyingColl.CopyTo(array, index);
 }
Exemplo n.º 5
0
 public void CopyTo(Array array, int index)
 {
     _collection.CopyTo(array, index);
 }
 /// <summary>Copies the contents of the collection to an array.</summary>
 /// <param name="array">The array to which the data should be copied.</param>
 /// <param name="index">The starting index at which data should be copied.</param>
 public void CopyTo(T[] array, int index)
 {
     _contained.CopyTo(array, index);
 }
Exemplo n.º 7
0
    // Test our implementation of IProducerConsumerCollection(T)
    // Demonstrates:
    //      IPCC(T).TryAdd()
    //      IPCC(T).TryTake()
    //      IPCC(T).CopyTo()
    static void TestSafeStack()
    {
        SafeStack <int> stack = new SafeStack <int>();
        IProducerConsumerCollection <int> ipcc = (IProducerConsumerCollection <int>)stack;

        // Test Push()/TryAdd()
        stack.Push(10); Console.WriteLine("Pushed 10");
        ipcc.TryAdd(20); Console.WriteLine("IPCC.TryAdded 20");
        stack.Push(15); Console.WriteLine("Pushed 15");

        int[] testArray = new int[3];

        // Try CopyTo() within boundaries
        try
        {
            ipcc.CopyTo(testArray, 0);
            Console.WriteLine("CopyTo() within boundaries worked, as expected");
        }
        catch (Exception e)
        {
            Console.WriteLine("CopyTo() within boundaries unexpectedly threw an exception: {0}", e.Message);
        }

        // Try CopyTo() that overflows
        try
        {
            ipcc.CopyTo(testArray, 1);
            Console.WriteLine("CopyTo() with index overflow worked, and it SHOULD NOT HAVE");
        }
        catch (Exception e)
        {
            Console.WriteLine("CopyTo() with index overflow threw an exception, as expected: {0}", e.Message);
        }

        // Test enumeration
        Console.Write("Enumeration (should be three items): ");
        foreach (int item in stack)
        {
            Console.Write("{0} ", item);
        }
        Console.WriteLine("");

        // Test TryPop()
        int popped = 0;

        if (stack.TryPop(out popped))
        {
            Console.WriteLine("Successfully popped {0}", popped);
        }
        else
        {
            Console.WriteLine("FAILED to pop!!");
        }

        // Test Count
        Console.WriteLine("stack count is {0}, should be 2", stack.Count);

        // Test TryTake()
        if (ipcc.TryTake(out popped))
        {
            Console.WriteLine("Successfully IPCC-TryTaked {0}", popped);
        }
        else
        {
            Console.WriteLine("FAILED to IPCC.TryTake!!");
        }
    }
Exemplo n.º 8
0
 /// <summary>
 /// Copies the current contents of the collection
 /// </summary>
 /// <param name="array">The destination array</param>
 /// <param name="index">The index at which copying begins</param>
 public void CopyTo(T[] array, int index) => _Collection.CopyTo(array, index);
Exemplo n.º 9
0
 public void CopyTo(Array array, int index)
 {
     _inner.CopyTo(array, index);
 }
 void ICollection.CopyTo(Array array, int index)
 {
     InnerCollection.CopyTo(array, index);
 }
Exemplo n.º 11
0
 public void CopyTo(T[] array, int index)
 {
     underlyingColl.CopyTo(array, index);
 }
Exemplo n.º 12
0
 public void CopyTo(Array array, int index)
 {
     _itemQueue.CopyTo(array, index);
 }