public void testIterator() { IEnumerator<Object> mock = new EmptyEnumerator<Object>(); Assert.IsFalse(mock.MoveNext()); try { mock.MoveNext(); Assert.Fail("Should have thrown InvalidOperationException"); } catch (System.InvalidOperationException) { // good } }
public void testIterator() { IEnumerator <Object> mock = new EmptyEnumerator <Object>(); Assert.IsFalse(mock.MoveNext()); try { mock.MoveNext(); Assert.Fail("Should have thrown InvalidOperationException"); } catch (System.InvalidOperationException) { // good } }
public static void Main() { var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < Iterations; i++) { IEnumerator enumerator = YieldBreak(); while (enumerator.MoveNext()) { throw new InvalidOperationException("Should not occur"); } } sw.Stop(); Console.WriteLine("Yield break: {0}", sw.Elapsed); GC.Collect(); sw.Restart(); for (int i = 0; i < Iterations; i++) { IEnumerator enumerator = Enumerable.Empty <object>().GetEnumerator(); while (enumerator.MoveNext()) { throw new InvalidOperationException("Should not occur"); } } sw.Stop(); Console.WriteLine("Enumerable.Empty<T>(): {0}", sw.Elapsed); GC.Collect(); sw.Restart(); var instance = new EmptyEnumerator(); for (int i = 0; i < Iterations; i++) { while (instance.MoveNext()) { throw new InvalidOperationException("Should not occur"); } } sw.Stop(); Console.WriteLine("EmptyEnumerator instance: {0}", sw.Elapsed); }