コード例 #1
0
        public void SparseArrayEnumerator3(int length)
        {
            Assert.AreNotEqual(default(int), 1);

            // Completely filled array
            ISparseArray <int> array = this.CreateInstance(length);

            Assert.AreEqual(length, array.Length);
            int[] actualArray = new int[length];
            for (int i = 0; i < array.Length; i++)
            {
                // Should have default value
                Assert.AreEqual(default(int), array[i]);

                // Set all entries
                array[i]       = 1;
                actualArray[i] = 1;
                Assert.AreEqual(1, array[i]);
            }

            IEnumerator <int> sparsEnumerator  = array.GetEnumerator();
            IEnumerator       actualEnumerator = actualArray.GetEnumerator();

            int index = -1;

            while (actualEnumerator.MoveNext())
            {
                index++;
                Assert.IsTrue(sparsEnumerator.MoveNext(), "Unable to move next at index " + index);
                Assert.AreEqual(actualEnumerator.Current, sparsEnumerator.Current, "Incorrect value at index " + index);
            }
            Assert.AreEqual(length - 1, index);
        }
コード例 #2
0
        public void SparseArrayEnumerator2(int length)
        {
            Assert.AreNotEqual(default(int), 1);

            // Completely sparse array i.e. no actual data
            ISparseArray <int> array = this.CreateInstance(length);

            Assert.AreEqual(length, array.Length);

            for (int i = 0; i < array.Length; i++)
            {
                // Should have default value
                Assert.AreEqual(default(int), array[i]);
            }

            IEnumerator <int> enumerator = array.GetEnumerator();

            int index = -1;

            while (enumerator.MoveNext())
            {
                index++;
                Assert.AreEqual(default(int), enumerator.Current, "Incorrect value at index " + index);
            }
            Assert.AreEqual(length - 1, index);
        }