コード例 #1
0
 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
     }
 }
コード例 #2
0
        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
            }
        }
コード例 #3
0
    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);
    }