title: Readable unit testing of a yielded sequence?
body: <p>Let's suppose I have some method that returns a <code>IEnumerable&lt;int&gt;</code> object. This methods make use of <code>yield return</code> keyword to produce a infinite sequence. Example of the Fibonacci algorithm :</p>
  
  <pre><code>public static IEnumerable&lt;long&gt; Fibonacci()
  {
      long x = 0L;
      long y = 1L;
      long z;
      yield return x;
      yield return y;
      while (true)
      {
          z = x + y;
          yield return z;
          y = x;
          x = z;
      }
  }
  </code></pre>
  
  <p>How can I properly create unit test for such sequence ? By proper I also mean readable.</p>
  
  <p>I can write unit tests like this :</p>
  
  <pre><code>[TestMethod]
  public void FibonacciTest()
  {
      var actual = MyClass.Fibonacci();
  
      var @enum = actual.GetEnumerator();
  
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 0);
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 1);
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 1);
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 2);
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 3);
      Assert.IsTrue(@enum.MoveNext();
      Assert.AreEqual(@enum.Current), 5);
      Assert.IsTrue(@enum.MoveNext();
  }
  </code></pre>
  
  <p>This test works, but I don't think it is readable. What are general (Fibonacci alogrithm was only a example) guidelines for writing unit tests for sequences ?</p>
  
  <p>PS: I'm using Visual Studio OOB Test suite + Pex.</p>