public void TemporaryBuffer_Add() { using var buffer = new TemporaryBuffer <int>(1); Assert.Equal(0, buffer.Count); buffer.Add(100); Assert.Equal(1, buffer.Count); Assert.True(buffer.EndsWith(100)); Assert.False(buffer.EndsWith(new [] { 100, 200 })); Assert.False(buffer.EndsWith(new [] { 100, 200, 300 })); Assert.Equal(100, buffer.Last()); buffer.Add(200); Assert.Equal(2, buffer.Count); Assert.False(buffer.EndsWith(100)); Assert.True(buffer.EndsWith(new [] { 100, 200 })); Assert.False(buffer.EndsWith(new [] { 100, 200, 300 })); Assert.Equal(200, buffer.Last()); buffer.DiscardLast(); Assert.Equal(1, buffer.Count); Assert.True(buffer.EndsWith(100)); Assert.False(buffer.EndsWith(new [] { 100, 200 })); Assert.False(buffer.EndsWith(new [] { 100, 200, 300 })); Assert.Equal(100, buffer.Last()); buffer.Add(200); buffer.Add(300); Assert.Equal(3, buffer.Count); Assert.False(buffer.EndsWith(100)); Assert.True(buffer.EndsWith(new [] { 200, 300 })); Assert.True(buffer.EndsWith(new [] { 100, 200, 300 })); Assert.Equal(300, buffer.Last()); }
public void TemporaryBuffer_DiscardLast() { using var buffer = new TemporaryBuffer <int>(1) { 100, 200, 300 }; buffer.DiscardLast(); Assert.Equal(new[] { 100, 200 }, buffer.ToArray()); }
public void TemporaryBuffer_CommitAfterDicard() { using var buffer = new TemporaryBuffer <int>(1) { 100, 200, 300 }; buffer.DiscardLast(); buffer.Add(700); buffer.Add(900); buffer.Discard(); var data = new List <int>(); buffer.Commit(data); Assert.Empty(data); }
public void TemporaryBuffer_Commit() { using var buffer = new TemporaryBuffer <int>(1) { 100, 200, 300 }; buffer.DiscardLast(); buffer.Add(700); buffer.Add(900); var data = new List <int>(); buffer.Commit(data); Assert.Equal(new List <int> { 100, 200, 700, 900 }, data); }