Ejemplo n.º 1
0
        public void SparseArrayEnumeratorTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(this.values);

            IEnumerator         enumerator                = this.values.GetEnumerator();
            IEnumerator <Int32> arrayEnumerator           = array.GetEnumerator();
            IEnumerator         arrayCollectionEnumerator = (array as IEnumerable).GetEnumerator();

            while (enumerator.MoveNext())
            {
                arrayEnumerator.MoveNext().ShouldBeTrue();
                arrayCollectionEnumerator.MoveNext().ShouldBeTrue();

                arrayEnumerator.Current.ShouldBe(enumerator.Current);
                arrayEnumerator.Current.ShouldBe(arrayCollectionEnumerator.Current);
            }

            arrayEnumerator.Reset();
            arrayCollectionEnumerator.Reset();

            while (arrayEnumerator.MoveNext())
            {
                arrayCollectionEnumerator.MoveNext().ShouldBeTrue();
                arrayEnumerator.Current.ShouldBe(arrayCollectionEnumerator.Current);
            }

            // exceptions
            array.Add(0);

            Should.Throw <InvalidOperationException>(() => arrayEnumerator.MoveNext());
            Should.Throw <InvalidOperationException>(() => arrayEnumerator.Reset());
        }
Ejemplo n.º 2
0
        public void EnumeratorTest()
        {
            IEnumerator <int> e = _array.GetEnumerator();

            for (int i = 0; i < _array.Count; i++)
            {
                Assert.True(e.MoveNext());
                Assert.Equal(_array[i], e.Current);
            }
        }
Ejemplo n.º 3
0
        public void Enumerating_GetEnumerator_Current_HasNotStarted() => Assert.ThrowsException <InvalidOperationException>(() =>
        {
            var expected = new[] { decimal.Zero, 1M, 2M, decimal.Zero };
            var sa       = new SparseArray <decimal>(expected);

            using (var e = sa.GetEnumerator())
            {
                var d = e.Current;
            }
        });
Ejemplo n.º 4
0
        public void Enumerating_GetEnumerator_Reset_ModifiedCollection() => Assert.ThrowsException <InvalidOperationException>(() =>
        {
            var expected = new[] { 1M, 2M, 3M, 4M };
            var sa       = new SparseArray <decimal>(expected);

            using (var e = sa.GetEnumerator())
            {
                e.MoveNext();
                sa[0] = decimal.Zero;
                e.Reset();
            }
        });
Ejemplo n.º 5
0
        public void GetEnumeratorTest()
        {
            var a = new SparseArray <bool> {
                [5] = true, [90] = false
            };

            using (var e = a.GetEnumerator())
            {
                Assert.That(e.MoveNext());
                Assert.That(e.Current, Is.True);
                Assert.That(e.MoveNext());
                Assert.That(e.Current, Is.False);
                Assert.That(e.MoveNext(), Is.False);
            }
        }
Ejemplo n.º 6
0
        public void Enumerating_GetEnumerator_Current_OK()
        {
            var expected = new[] { 1M, 2M, 3M, 4M };
            var sa       = new SparseArray <decimal>(expected);

            using (var e = sa.GetEnumerator())
            {
                Assert.IsNotNull(e, "Failed to return enumerator");
                Assert.IsTrue(e.MoveNext(), "Failed to move to first element in SparseArray");

                var d = e.Current;

                Assert.AreEqual(decimal.One, d, "Incorrect value returned from Enuermator.Current");
            }
        }
Ejemplo n.º 7
0
        public void Enumerating_GetEnumerator_Reset_OK()
        {
            var expected = new[] { 1M, 2M, 3M, 4M };
            var sa       = new SparseArray <decimal>(expected);

            using (var e = sa.GetEnumerator())
            {
                while (e.MoveNext())
                {
                    ;
                }

                e.Reset();

                Assert.IsTrue(e.MoveNext(), "Failed to move to the first element after Reset()");
                Assert.AreEqual(decimal.One, e.Current, "Incorrect value at current location");
            }
        }
Ejemplo n.º 8
0
        public void SparseArrayEnumeratorTest()
        {
            SparseArray <Int32> array = new SparseArray <Int32>(_values);

            IEnumerator         enumerator                = _values.GetEnumerator();
            IEnumerator <Int32> arrayEnumerator           = array.GetEnumerator();
            IEnumerator         arrayCollectionEnumerator = (array as IEnumerable).GetEnumerator();

            while (enumerator.MoveNext())
            {
                Assert.IsTrue(arrayEnumerator.MoveNext());
                Assert.IsTrue(arrayCollectionEnumerator.MoveNext());

                Assert.AreEqual(enumerator.Current, arrayEnumerator.Current);
                Assert.AreEqual(arrayCollectionEnumerator.Current, arrayEnumerator.Current);
            }


            arrayEnumerator.Reset();
            arrayCollectionEnumerator.Reset();

            while (arrayEnumerator.MoveNext())
            {
                Assert.IsTrue(arrayCollectionEnumerator.MoveNext());
                Assert.AreEqual(arrayCollectionEnumerator.Current, arrayEnumerator.Current);
            }


            // exceptions

            array.Add(0);

            Assert.Throws <InvalidOperationException>(() => arrayEnumerator.MoveNext());
            Assert.Throws <InvalidOperationException>(() => arrayEnumerator.Reset());

            arrayEnumerator.Dispose();

            Assert.Throws <ObjectDisposedException>(() => arrayEnumerator.MoveNext());

            arrayEnumerator.Dispose();
        }