public void Iterator_Index() { var bytes = Encoding.UTF8.GetBytes("01234567890123456789"); var iterator = new ByteInputIterator(bytes); Assert.IsTrue(iterator.Index == 0); Assert.IsTrue(iterator.Length == bytes.Length); for (int i = 0; i < bytes.Length; i++) { Assert.IsTrue(iterator.Index == i); Assert.IsTrue(iterator.Current() == bytes[i]); if (i < bytes.Length - 1) { Assert.IsTrue(iterator.Next() == bytes[i + 1]); } } for (int i = bytes.Length - 1; i >= 0; i--) { Assert.IsTrue(iterator.Index == i); Assert.IsTrue(iterator.Current() == bytes[i]); if (i > 0) { Assert.IsTrue(iterator.Previous() == bytes[i - 1]); } } }
public void Iterator_Initialization() { var input = "01234567890123456789"; var bytes = Encoding.UTF8.GetBytes(input); var iterator = new ByteInputIterator(bytes); // tests that iterator begins at zero based index Assert.IsTrue(iterator.Index == 0); Assert.IsTrue(iterator.Length == 20); Assert.IsTrue(iterator.Current() == '0'); Assert.IsTrue(iterator.Next() == '1'); Assert.IsTrue(iterator.Previous() == '0'); Assert.IsTrue(bytes.SequenceEqual(iterator.Text(0, 19)), "Text unable to return complete input."); }
public void Iterator_OutofRange() { var bytes = Encoding.UTF8.GetBytes(""); var iterator = new ByteInputIterator(bytes); Assert.IsTrue(iterator.Index == 0); Assert.IsTrue(iterator.Length == 0); Assert.IsTrue(iterator.Current() == -1); Assert.IsTrue(iterator.Index == 0); Assert.IsTrue(iterator.Next() == -1); Assert.IsTrue(iterator.Index == 0); Assert.IsTrue(iterator.Previous() == -1); Assert.IsTrue(iterator.Index == 0); }