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()); }
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); } }
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; } });
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(); } });
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); } }
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"); } }
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"); } }
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(); }