public void RemoveCurrent() { var list = new SinglyLinkedList <int>(); list.AddAll(1, 2, 3, 4, 5); var enumerator = list.GetEnumerator(); Assert.True(enumerator.MoveNext()); enumerator.RemoveCurrent(); Assert.Equal(4, list.Count); Assert.Null(enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(2, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(3, enumerator.Current); enumerator.RemoveCurrent(); Assert.Equal(3, list.Count); Assert.Equal(2, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.True(enumerator.MoveNext()); Assert.Equal(5, enumerator.Current); enumerator.RemoveCurrent(); Assert.Equal(2, list.Count); Assert.Equal(4, enumerator.Current); Assert.False(enumerator.MoveNext()); Assert.Null(enumerator.Current); Assert.Equal(new int[] { 2, 4 }, list.WalkToList()); Assert.Equal(new int[] { 2, 4 }, list.EnumerateToList()); }
public void MoveToFront() { var list = new SinglyLinkedList <int>(); list.AddAll(1, 2, 3, 4, 5); var enumerator = list.GetEnumerator(); Assert.True(enumerator.MoveNext()); enumerator.MoveCurrentToFront(); // Should be moved back in front Assert.Null(enumerator.Current); Assert.Equal(5, list.Count); Assert.True(enumerator.MoveNext()); Assert.Equal(1, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(2, enumerator.Current); enumerator.MoveCurrentToFront(); Assert.Equal(1, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(3, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(4, enumerator.Current); Assert.True(enumerator.MoveNext()); Assert.Equal(5, enumerator.Current); enumerator.MoveCurrentToFront(); Assert.Equal(4, enumerator.Current); Assert.False(enumerator.MoveNext()); Assert.Null(enumerator.Current); Assert.Equal(5, list !.First); Assert.Equal(new int[] { 5, 2, 1, 3, 4 }, list.WalkToList()); Assert.Equal(new int[] { 5, 2, 1, 3, 4 }, list.EnumerateToList()); }