public void PutMultipleTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected1; string expected2; string expected3; target = new CircularBuffer <string>(10); expected1 = "Alpha"; expected2 = "Beta"; expected3 = "Gamma"; expectedHead = 0; expectedSize = 3; expectedTail = 3; // act target.Put(expected1); target.Put(expected2); target.Put(expected3); // assert Assert.IsTrue(target.Contains(expected1)); Assert.IsTrue(target.Contains(expected2)); Assert.IsTrue(target.Contains(expected3)); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void CopyToTest() { // arrange CircularBuffer <string> target; int expectedHead; string[] expected; string[] actual; target = new CircularBuffer <string>(10); expected = new[] { "Alpha", "Beta", "Gamma" }; expectedHead = 0; actual = new string[3]; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.CopyTo(actual); // assert CollectionAssert.AreEqual(expected, actual); Assert.IsTrue(target.Contains("Alpha")); Assert.IsTrue(target.Contains("Beta")); Assert.IsTrue(target.Contains("Gamma")); Assert.AreEqual(expectedHead, target.Head); }
public void GetTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected; string actual; target = new CircularBuffer <string>(10); expected = "Alpha"; expectedHead = 1; expectedSize = 2; expectedTail = 3; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actual = target.Get(); // assert Assert.AreEqual(expected, actual); Assert.IsFalse(target.Contains("Alpha")); Assert.IsTrue(target.Contains("Beta")); Assert.IsTrue(target.Contains("Gamma")); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void CopyToArrayWithStartingIndexOffsetAndCountTest() { // arrange CircularBuffer <string> target; int expectedHead; string[] expected; string[] actual; int offset; int count; int index; target = new CircularBuffer <string>(10); expected = new[] { "Zeta", "Beta", "Gamma", "Eta" }; actual = new[] { "Zeta", null, null, "Eta" }; expectedHead = 0; index = 1; offset = 1; count = 2; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.CopyTo(index, actual, offset, count); // assert actual.Should(). Equal(expected); target.Contains("Alpha"). Should(). BeTrue(); target.Contains("Beta"). Should(). BeTrue(); target.Contains("Gamma"). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); }
public void TestContains() { var buffer = new CircularBuffer <int>(3); Assert.IsFalse(buffer.Contains(1)); buffer.Add(1); Assert.IsTrue(buffer.Contains(1)); Assert.IsFalse(buffer.Contains(2)); buffer.Remove(); Assert.IsFalse(buffer.Contains(1)); buffer.Add(1); buffer.Add(2); buffer.Add(3); Assert.IsTrue(buffer.Contains(1)); buffer.Remove(); Assert.IsFalse(buffer.Contains(1)); Assert.IsTrue(buffer.Contains(2)); Assert.IsTrue(buffer.Contains(3)); buffer.Add(4); Assert.IsTrue(buffer.Contains(4)); }
public void GetWithArrayTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; int expectedElements; int actualElements; string[] expected; string[] actual; target = new CircularBuffer <string>(10); expected = new[] { "Alpha", "Beta" }; expectedHead = 2; expectedSize = 1; expectedTail = 3; expectedElements = 2; actual = new string[expectedElements]; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actualElements = target.Get(actual); // assert actualElements.Should(). Be(expectedElements); actual.Should(). Equal(expected); target.Contains("Alpha"). Should(). BeFalse(); target.Contains("Beta"). Should(). BeFalse(); target.Contains("Gamma"). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); target.Tail.Should(). Be(expectedTail); target.Size.Should(). Be(expectedSize); }
public void CopyToArrayWithOffsetTest() { // arrange CircularBuffer <string> target; int expectedHead; string[] expected; string[] actual; int offset; target = new CircularBuffer <string>(10); expected = new[] { "Zeta", "Alpha", "Beta", "Gamma" }; actual = new[] { "Zeta", null, null, null }; expectedHead = 0; offset = 1; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.CopyTo(actual, offset); // assert actual.Should(). Equal(expected); target.Contains("Alpha"). Should(). BeTrue(); target.Contains("Beta"). Should(). BeTrue(); target.Contains("Gamma"). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); }
public void CircularBuffer_Enqueue() { var buffer = new CircularBuffer<string>(10); buffer.Enqueue("test"); buffer.Enqueue("string"); CollectionAssert.AreEqual(new[] { "test", "string" }, buffer.ToArray()); Assert.AreEqual(2, buffer.Count); Assert.AreEqual(10, buffer.Capacity); Assert.AreEqual(0, buffer.Head); Assert.AreEqual(2, buffer.Tail); Assert.IsTrue(buffer.Contains("string")); Assert.IsFalse(buffer.Contains("other string")); }
public void GetWithArrayAndOffsetTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; int expectedElements; int actualElements; string[] expected; string[] actual; int offset; target = new CircularBuffer <string>(10); expected = new[] { null, "Alpha", "Beta" }; expectedHead = 2; expectedSize = 2; expectedTail = 4; expectedElements = 2; offset = 1; actual = new string[3]; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); target.Put("Delta"); // act actualElements = target.Get(actual, offset, expectedElements); // assert Assert.AreEqual(expectedElements, actualElements); CollectionAssert.AreEqual(expected, actual); Assert.IsFalse(target.Contains("Alpha")); Assert.IsFalse(target.Contains("Beta")); Assert.IsTrue(target.Contains("Gamma")); Assert.IsTrue(target.Contains("Delta")); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void Remove_ValueType_RemovesItem() { var buffer = new CircularBuffer<int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Remove(2); Assert.AreEqual(2, buffer.Count); Assert.IsTrue(buffer.Contains(1)); Assert.IsFalse(buffer.Contains(2)); Assert.IsTrue(buffer.Contains(3)); }
public void Remove_ValueType_RemovesItem() { var buffer = new CircularBuffer <int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Remove(2); Assert.AreEqual(2, buffer.Count); Assert.IsTrue(buffer.Contains(1)); Assert.IsFalse(buffer.Contains(2)); Assert.IsTrue(buffer.Contains(3)); }
public void PutWrapBufferTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected1; string expected2; string expected3; string expected4; target = new CircularBuffer <string>(3); expected1 = "Alpha"; expected2 = "Beta"; expected3 = "Gamma"; expected4 = "Delta"; expectedHead = 1; expectedSize = 3; expectedTail = 1; // act target.Put(expected1); target.Put(expected2); target.Put(expected3); target.Put(expected4); // assert target.Contains(expected1). Should(). BeFalse(); target.Contains(expected2). Should(). BeTrue(); target.Contains(expected3). Should(). BeTrue(); target.Contains(expected4). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); target.Tail.Should(). Be(expectedTail); target.Size.Should(). Be(expectedSize); }
public void CopyToArrayWithOffsetAndCountTest() { // arrange CircularBuffer <string> target; int expectedHead; string[] expected; string[] actual; int offset; int count; int index; target = new CircularBuffer <string>(10); expected = new[] { "Zeta", "Alpha", "Beta", "Eta" }; actual = new[] { "Zeta", null, null, "Eta" }; expectedHead = 0; index = 0; offset = 1; count = 2; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.CopyTo(index, actual, offset, count); // assert CollectionAssert.AreEqual(expected, actual); Assert.IsTrue(target.Contains("Alpha")); Assert.IsTrue(target.Contains("Beta")); Assert.IsTrue(target.Contains("Gamma")); Assert.AreEqual(expectedHead, target.Head); }
public static void TestingICollectionImplementation() { var circularBuffer = new CircularBuffer <byte>(3, false); circularBuffer.Add(3); circularBuffer.Add(34); circularBuffer.Add(24); //Testing contains Assert.True(circularBuffer.Contains(3)); //Testing CopyTo var array = new byte[3]; circularBuffer.CopyTo(array, 0); Assert.Equal(3, array[0]); Assert.Equal(34, array[1]); Assert.Equal(24, array[2]); //Testing Count Assert.Equal(3, circularBuffer.Count); //Testing clear circularBuffer.Clear(); Assert.Equal(0, circularBuffer.Pop()); Assert.Equal(0, circularBuffer.Pop()); Assert.Equal(0, circularBuffer.Pop()); Assert.Empty(circularBuffer); }
public void PutTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected; target = new CircularBuffer <string>(10); expected = "Alpha"; expectedHead = 0; expectedSize = 1; expectedTail = 1; // act target.Put(expected); // assert target.Contains(expected). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); target.Tail.Should(). Be(expectedTail); target.Size.Should(). Be(expectedSize); }
public void PutTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected; target = new CircularBuffer <string>(10); expected = "Alpha"; expectedHead = 0; expectedSize = 1; expectedTail = 1; // act target.Put(expected); // assert Assert.IsTrue(target.Contains(expected)); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void CircularBuffer_Dequeue() { int[] data = { 0, 1, 2, 3 }; var buffer = new CircularBuffer<int>(data.Length); buffer.EnqueueRange(data, 0, data.Length); buffer.Dequeue(); Assert.AreEqual(3, buffer.Count); Assert.AreEqual(data.Length, buffer.Capacity); Assert.AreEqual(1, buffer.Head); Assert.AreEqual(0, buffer.Tail); Assert.IsTrue(buffer.Contains(1)); Assert.IsFalse(buffer.Contains(0)); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, buffer.ToArray()); }
public void ContainsInt_ValueExists_ReturnsTrue() { var buffer = new CircularBuffer <int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Add(4); buffer.Add(5); buffer.Add(6); buffer.Add(7); buffer.Add(8); Assert.IsTrue(buffer.Contains(6)); Assert.IsTrue(buffer.Contains(7)); Assert.IsTrue(buffer.Contains(8)); }
public void Remove_ReferenceType_RemovesItem() { var buffer = new CircularBuffer<TestRefType>(3); var o1 = new TestRefType(Guid.NewGuid()); var o2 = new TestRefType(Guid.NewGuid()); var o3 = new TestRefType(Guid.NewGuid()); buffer.Add(o1); buffer.Add(o2); buffer.Add(o3); buffer.Remove(o2); Assert.AreEqual(2, buffer.Count); Assert.IsTrue(buffer.Contains(o1)); Assert.IsFalse(buffer.Contains(o2)); Assert.IsTrue(buffer.Contains(o3)); }
public void Remove_ReferenceType_RemovesItem() { var buffer = new CircularBuffer <TestRefType>(3); var o1 = new TestRefType(Guid.NewGuid()); var o2 = new TestRefType(Guid.NewGuid()); var o3 = new TestRefType(Guid.NewGuid()); buffer.Add(o1); buffer.Add(o2); buffer.Add(o3); buffer.Remove(o2); Assert.AreEqual(2, buffer.Count); Assert.IsTrue(buffer.Contains(o1)); Assert.IsFalse(buffer.Contains(o2)); Assert.IsTrue(buffer.Contains(o3)); }
public void ContainsRefType_ValueExists_ReturnsTrue() { var buffer = new CircularBuffer <TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); buffer.Add(new TestRefType(id4)); Assert.IsTrue(buffer.Contains(new TestRefType(id2))); Assert.IsTrue(buffer.Contains(new TestRefType(id3))); Assert.IsTrue(buffer.Contains(new TestRefType(id4))); }
public void GetTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected; string actual; target = new CircularBuffer <string>(10); expected = "Alpha"; expectedHead = 1; expectedSize = 2; expectedTail = 3; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actual = target.Get(); // assert actual.Should(). Be(expected); target.Contains("Alpha"). Should(). BeFalse(); target.Contains("Beta"). Should(). BeTrue(); target.Contains("Gamma"). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); target.Tail.Should(). Be(expectedTail); target.Size.Should(). Be(expectedSize); }
public void CopyToTest() { // arrange CircularBuffer <string> target; int expectedHead; string[] expected; string[] actual; target = new CircularBuffer <string>(10); expected = new[] { "Alpha", "Beta", "Gamma" }; expectedHead = 0; actual = new string[3]; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.CopyTo(actual); // assert actual.Should(). Equal(expected); target.Contains("Alpha"). Should(). BeTrue(); target.Contains("Beta"). Should(). BeTrue(); target.Contains("Gamma"). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); }
public void PutMultipleTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected1; string expected2; string expected3; target = new CircularBuffer <string>(10); expected1 = "Alpha"; expected2 = "Beta"; expected3 = "Gamma"; expectedHead = 0; expectedSize = 3; expectedTail = 3; // act target.Put(expected1); target.Put(expected2); target.Put(expected3); // assert target.Contains(expected1). Should(). BeTrue(); target.Contains(expected2). Should(). BeTrue(); target.Contains(expected3). Should(). BeTrue(); target.Head.Should(). Be(expectedHead); target.Tail.Should(). Be(expectedTail); target.Size.Should(). Be(expectedSize); }
public void ContainsDefaultRefType_NotYetFull_ReturnsFalse() { var buffer = new CircularBuffer <TestRefType>(3); buffer.Add(new TestRefType(Guid.NewGuid())); buffer.Add(new TestRefType(Guid.NewGuid())); var result = buffer.Contains(default(TestRefType)); Assert.IsFalse(result); }
public void ContainsDefaultInt_NotYetFull_ReturnsFalse() { var buffer = new CircularBuffer <int>(3); buffer.Add(1); buffer.Add(2); var result = buffer.Contains(default(int)); Assert.IsFalse(result); }
public void GetLast_should_not_affect_existing_items() { // arrange CircularBuffer <string> target; bool actual1; bool actual2; target = new CircularBuffer <string>(10); target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act target.GetLast(); // assert actual1 = target.Contains("Alpha"); actual2 = target.Contains("Beta"); Assert.IsTrue(actual1); Assert.IsTrue(actual2); }
public void GetWithCountTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string[] expected; string[] actual; target = new CircularBuffer <string>(10); expected = new[] { "Alpha", "Beta" }; expectedHead = 2; expectedSize = 1; expectedTail = 3; target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actual = target.Get(2); // assert CollectionAssert.AreEqual(expected, actual); Assert.IsFalse(target.Contains("Alpha")); Assert.IsFalse(target.Contains("Beta")); Assert.IsTrue(target.Contains("Gamma")); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void ContainsRefType_NullDoesNotExist_ReturnsTrue() { var buffer = new CircularBuffer <TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); Assert.IsFalse(buffer.Contains(null)); }
public void PutWrapBufferTest() { // arrange CircularBuffer <string> target; int expectedSize; int expectedHead; int expectedTail; string expected1; string expected2; string expected3; string expected4; target = new CircularBuffer <string>(3); expected1 = "Alpha"; expected2 = "Beta"; expected3 = "Gamma"; expected4 = "Delta"; expectedHead = 1; expectedSize = 3; expectedTail = 1; // act target.Put(expected1); target.Put(expected2); target.Put(expected3); target.Put(expected4); // assert Assert.IsFalse(target.Contains(expected1)); Assert.IsTrue(target.Contains(expected2)); Assert.IsTrue(target.Contains(expected3)); Assert.IsTrue(target.Contains(expected4)); Assert.AreEqual(expectedHead, target.Head); Assert.AreEqual(expectedTail, target.Tail); Assert.AreEqual(expectedSize, target.Size); }
public void ContainsTest() { // arrange CircularBuffer <string> target; bool actual; target = new CircularBuffer <string>(10); target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actual = target.Contains("Alpha"); // assert Assert.IsTrue(actual); }
public void ContainsInt_ValueDoesNotExist_ReturnsFalse() { var buffer = new CircularBuffer <int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Add(4); buffer.Add(5); buffer.Add(6); buffer.Add(7); buffer.Add(8); var result = buffer.Contains(3); Assert.IsFalse(result); }
public void ContainsNegativeTest() { // arrange CircularBuffer <string> target; bool actual; target = new CircularBuffer <string>(10); target.Put("Alpha"); target.Put("Beta"); target.Put("Gamma"); // act actual = target.Contains("Delta"); // assert actual.Should(). BeFalse(); }
public void ContainsRefType_ValueDoesNotExist_ReturnsFalse() { var buffer = new CircularBuffer <TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); buffer.Add(new TestRefType(id4)); var result = buffer.Contains(new TestRefType(id1)); Assert.IsFalse(result); }
public void ContainsInt_ValueDoesNotExist_ReturnsFalse() { var buffer = new CircularBuffer<int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Add(4); buffer.Add(5); buffer.Add(6); buffer.Add(7); buffer.Add(8); var result = buffer.Contains(3); Assert.IsFalse(result); }
public void CircularBuffer_EnqueueAfterTrimExcess() { var buffer = new CircularBuffer<string>(10); buffer.EnqueueRange(new[] { "a", "b", "c" }, 0, 3); buffer.TrimExcess(); buffer.Enqueue("z"); CollectionAssert.AreEqual(new[] { "z", "b", "c" }, buffer.ToArray()); Assert.AreEqual(3, buffer.Count); Assert.AreEqual(3, buffer.Capacity); Assert.AreEqual(0, buffer.Head); Assert.AreEqual(1, buffer.Tail); Assert.IsTrue(buffer.Contains("z")); Assert.IsFalse(buffer.Contains("a")); }
public void ContainsDefaultInt_NotYetFull_ReturnsFalse() { var buffer = new CircularBuffer<int>(3); buffer.Add(1); buffer.Add(2); var result = buffer.Contains(default(int)); Assert.IsFalse(result); }
public void ContainsInt_ValueExists_ReturnsTrue() { var buffer = new CircularBuffer<int>(3); buffer.Add(1); buffer.Add(2); buffer.Add(3); buffer.Add(4); buffer.Add(5); buffer.Add(6); buffer.Add(7); buffer.Add(8); Assert.IsTrue(buffer.Contains(6)); Assert.IsTrue(buffer.Contains(7)); Assert.IsTrue(buffer.Contains(8)); }
public void ContainsDefaultRefType_NotYetFull_ReturnsFalse() { var buffer = new CircularBuffer<TestRefType>(3); buffer.Add(new TestRefType(Guid.NewGuid())); buffer.Add(new TestRefType(Guid.NewGuid())); var result = buffer.Contains(default(TestRefType)); Assert.IsFalse(result); }
public void ContainsRefType_NullDoesNotExist_ReturnsTrue() { var buffer = new CircularBuffer<TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); Assert.IsFalse(buffer.Contains(null)); }
public void ContainsRefType_ValueExists_ReturnsTrue() { var buffer = new CircularBuffer<TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); buffer.Add(new TestRefType(id4)); Assert.IsTrue(buffer.Contains(new TestRefType(id2))); Assert.IsTrue(buffer.Contains(new TestRefType(id3))); Assert.IsTrue(buffer.Contains(new TestRefType(id4))); }
public void CircularBuffer_EnqueueOverwriteAllowed() { string[] data = { "a", "b", "c", "d" }; var buffer = new CircularBuffer<string>(data.Length); buffer.EnqueueRange(data, 0, data.Length); buffer.Enqueue("z"); CollectionAssert.AreEqual(new[] { "z", "b", "c", "d" }, buffer.ToArray()); Assert.AreEqual(data.Length, buffer.Count); Assert.AreEqual(data.Length, buffer.Capacity); Assert.AreEqual(0, buffer.Head); Assert.AreEqual(1, buffer.Tail); Assert.IsTrue(buffer.Contains("z")); Assert.IsFalse(buffer.Contains("a")); }
public void ContainsRefType_ValueDoesNotExist_ReturnsFalse() { var buffer = new CircularBuffer<TestRefType>(3); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); buffer.Add(new TestRefType(id1)); buffer.Add(new TestRefType(id2)); buffer.Add(new TestRefType(id3)); buffer.Add(new TestRefType(id4)); var result = buffer.Contains(new TestRefType(id1)); Assert.IsFalse(result); }