本文整理汇总了C#中RingBuffer.Add方法的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer.Add方法的具体用法?C# RingBuffer.Add怎么用?C# RingBuffer.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RingBuffer
的用法示例。
在下文中一共展示了RingBuffer.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddItemsToBufferOfSetSize_RemovesItemsFirstAddedToBufferToFitInMoreItems
public void AddItemsToBufferOfSetSize_RemovesItemsFirstAddedToBufferToFitInMoreItems()
{
var buffer = new RingBuffer<string>(2);
buffer.Add("1");
buffer.Add("2");
List<string> items = buffer.ToList();
Assert.AreEqual("1", items[0]);
Assert.AreEqual("2", items[1]);
buffer.Add("3");
items = buffer.ToList();
Assert.AreEqual("2", items[0]);
Assert.AreEqual("3", items[1]);
buffer.Add("4");
items = buffer.ToList();
Assert.AreEqual("3", items[0]);
Assert.AreEqual("4", items[1]);
buffer.Add("5");
items = buffer.ToList();
Assert.AreEqual("4", items[0]);
Assert.AreEqual("5", items[1]);
}
示例2: IsFullTest_True
public void IsFullTest_True()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(1);
rb.Add(2);
rb.Add(3);
rb.Add(4);
Assert.IsTrue(rb.IsFull);
}
示例3: ReadingFromARingBuffer
public void ReadingFromARingBuffer()
{
RingBuffer<int> r = new RingBuffer<int>(3);
r.Add(1);
r.Add(2);
r.Add(3);
r.Add(4);
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(4, r[0]);
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(2, r[1]);
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(3, r[2]);
}
示例4: ClearTest_notempty
public void ClearTest_notempty()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(7);
Assert.IsFalse(rb.IsEmpty);
rb.Clear();
Assert.IsTrue(rb.IsEmpty);
}
示例5: PutIncrementsSize
public void PutIncrementsSize() {
RingBuffer<int> _buffer = new RingBuffer<int>(iterations);
for(int i = 0; i < iterations; i++) {
int _tmp = i;
_buffer.Add(_tmp);
Assert.AreEqual(i + 1, _buffer.Size, "Size is not equal to number of elements added.");
}
}
示例6: AddItemsToBufferOfSetSize_IncreasesSizeUntilFull
public void AddItemsToBufferOfSetSize_IncreasesSizeUntilFull()
{
var buffer = new RingBuffer<string>(2);
Assert.AreEqual(0, buffer.Count);
buffer.Add("1");
Assert.AreEqual(1, buffer.Count);
buffer.Add("2");
Assert.AreEqual(2, buffer.Count);
buffer.Add("3");
Assert.AreEqual(2, buffer.Count);
}
示例7: Sensor
public Sensor(SensorIdentification config)
{
mID = config.Id;
mMAC = config.Mac;
mPortName = config.PortName;
mData = new RingBuffer<SensorDataEntry>(HISTORY_BUFFER_SIZE);
/** Add an empty entry in case getLastEntry is called before data comes in */
mData.Add( new SensorDataEntry() );
mTimeoutWatch = new System.Diagnostics.Stopwatch();
}
示例8: AddingToARingBufferWorks
public void AddingToARingBufferWorks()
{
RingBuffer<int> r = new RingBuffer<int>(5);
r.Add(1);
r.Add(2);
r.Add(3);
r.Add(4);
r.Add(5);
r.Add(6);
}
示例9: AddValue
/// <summary>
/// Registers one tick for the given name.
/// </summary>
/// <param name="name">A string identifying the caller.</param>
/// <param name="value">The new value.</param>
public void AddValue(string name, int val)
{
RingBuffer<int> rb;
if (fps.ContainsKey(name)) {
rb = fps[name];
} else {
rb = new RingBuffer<int>(FPS_WINDOW);
// Fill the RingBuffer with sentinel values so we don't have to
// do extra bookkeeping.
for (int i = 0; i < FPS_WINDOW; i++) {
rb.Add(-1);
}
fps.Add(name, rb);
}
lock (rb) {
rb.Add(val);
}
}
示例10: populateBuffer
private void populateBuffer(int elements, RingBuffer<int> buffer) {
for(int i = 0; i < elements; i++) {
buffer.Add(i);
}
}
示例11: ContainsReturnsCorrectly
public void ContainsReturnsCorrectly() {
RingBuffer<int> _buffer = new RingBuffer<int>(iterations + 2);
_buffer.Add(knownValue - 1);
bool _containsKnownValue = _buffer.Contains(knownValue);
Assert.AreEqual(false, _containsKnownValue);
populateBuffer(iterations, _buffer);
_buffer.Add(knownValue);
_containsKnownValue = _buffer.Contains(knownValue);
Assert.AreEqual(true, _containsKnownValue);
}
示例12: PeekTest_1
public void PeekTest_1()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(3);
rb.Add(5);
int p1 = rb.Peek();
int d1 = rb.Remove();
int p2 = rb.Peek();
int d2 = rb.Remove();
Assert.AreEqual(3, p1);
Assert.AreEqual(5, p2);
Assert.AreEqual(3, d1);
Assert.AreEqual(5, d2);
}
示例13: IsFullTest_False_2
public void IsFullTest_False_2()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(4);
Assert.IsFalse(rb.IsFull);
}
示例14: IsEmptyTest_False
public void IsEmptyTest_False()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(4);
Assert.IsFalse(rb.IsEmpty);
}
示例15: QueueTest_3
public void QueueTest_3()
{
RingBuffer<int> rb = new RingBuffer<int>(4);
rb.Add(2);
rb.Add(4);
rb.Add(6);
rb.Add(8);
rb.Add(9);
int d1 = rb.Remove();
int d2 = rb.Remove();
int d3 = rb.Remove();
int d4 = rb.Remove();
Assert.AreEqual(4, d1);
Assert.AreEqual(6, d2);
Assert.AreEqual(8, d3);
Assert.AreEqual(9, d4);
Assert.IsTrue(rb.IsEmpty);
}