本文整理汇总了C#中CircularBuffer.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Add方法的具体用法?C# CircularBuffer.Add怎么用?C# CircularBuffer.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTrail
public void CreateTrail(Vector3 from, Vector3 to, float distanceBetweenPoints)
{
float num = Vector3.Distance(from, to);
Vector3 normalized = (to - from).normalized;
float num2 = 0f;
CircularBuffer<PCTrailPoint> circularBuffer = new CircularBuffer<PCTrailPoint>(this.GetMaxNumberOfPoints());
int num3 = 0;
while (num2 < num)
{
PCTrailPoint pCTrailPoint = new PCTrailPoint();
pCTrailPoint.PointNumber = num3;
pCTrailPoint.Position = from + normalized * num2;
circularBuffer.Add(pCTrailPoint);
this.InitialiseNewPoint(pCTrailPoint);
num3++;
if (distanceBetweenPoints <= 0f)
{
break;
}
num2 += distanceBetweenPoints;
}
PCTrailPoint pCTrailPoint2 = new PCTrailPoint();
pCTrailPoint2.PointNumber = num3;
pCTrailPoint2.Position = to;
circularBuffer.Add(pCTrailPoint2);
this.InitialiseNewPoint(pCTrailPoint2);
PCTrail pCTrail = new PCTrail(this.GetMaxNumberOfPoints());
pCTrail.Points = circularBuffer;
this._fadingTrails.Add(pCTrail);
}
示例2: ShouldSaveWithoutOverflow
public void ShouldSaveWithoutOverflow()
{
var buffer = new CircularBuffer<int>(5);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
CollectionAssert.AreEqual(new [] { 1, 2, 3 }, buffer);
}
示例3: YieldSign
/*
* coroutine
IEnumerator YieldSign() {
print ("spawn yield symbol");
yield return new WaitForSeconds(2);
PowerSpawn();
}
void PowerSpawn(){
print ("spawn power");
}
void Start() {
StartCoroutine(YieldSign());
print ("disable button");
}
*/
void Start(){
CircularBuffer<int> buffer = new CircularBuffer<int>(2);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
foreach(int i in buffer.Reverse<int>()){
print (i);
}
}
示例4: Add_MoreThanCapacity_ProperlyCircles
public void Add_MoreThanCapacity_ProperlyCircles()
{
var buffer = new CircularBuffer<int>(3);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
buffer.Add(4);
Assert.AreEqual(2, buffer.Skip(0).First());
Assert.AreEqual(3, buffer.Skip(1).First());
Assert.AreEqual(4, buffer.Skip(2).First());
}
示例5: Remove_RemoveSecondItemAndAddTwoItems_OrderIsRight
public void Remove_RemoveSecondItemAndAddTwoItems_OrderIsRight()
{
//Create a circular buffer where the first item is overridden
var target = new CircularBuffer<int>(3) { 1, 2, 3, 4 };
target.Remove(2);
target.Add(5);
target.Add(6);
var expected = new List<int> { 6, 3, 5 };
Assert.IsTrue(target.SequenceEqual(expected));
Assert.IsTrue(target.Capacity == 3);
}
示例6: Remove_ValueType_RemovesItem
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));
}
示例7: TestRollover
public void TestRollover()
{
int bufferSize = 3;
CircularBuffer<int> circularBuffer = new CircularBuffer<int>(bufferSize);
for (int i = 0; i < 3; i++)
{
circularBuffer.Add(i);
VerifyContent(circularBuffer, 0, i);
}
for (int i = 3; i < 8; i++)
{
circularBuffer.Add(i);
VerifyContent(circularBuffer, i - bufferSize + 1, i);
}
}
示例8: Remove_ReferenceType_RemovesItem
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));
}
示例9: ShouldSaveWithOverflow
public void ShouldSaveWithOverflow()
{
var buffer = new CircularBuffer<int>(4);
for(var i = 0; i < 6; i++)
{
buffer.Add(i);
}
Assert.AreEqual(buffer, new [] { 3, 4, 5 });
}
示例10: TestAccessByIndex
public void TestAccessByIndex()
{
int bufferSize = 3;
CircularBuffer<int> circularBuffer = new CircularBuffer<int>(bufferSize);
for (int i = 0; i < 3; i++)
{
circularBuffer.Add(i);
}
// not rolled over yet
Assert.AreEqual(1, circularBuffer[1]);
for (int i = 3; i < 8; i++)
{
circularBuffer.Add(i);
}
// rolled over
Assert.AreEqual(6, circularBuffer[1]);
}
示例11: ShouldSaveWithOverflowArray
public void ShouldSaveWithOverflowArray()
{
var buffer = new CircularBuffer<int>(4);
for(var i = 0; i < 6; i++)
{
buffer.Add(i);
}
var result = new [] { 3, 4, 5 };
var copy = new int[3];
buffer.CopyTo(copy, 0);
Assert.AreEqual(result, copy);
}
示例12: ShouldSaveWithoutOverflowArray
public void ShouldSaveWithoutOverflowArray()
{
var buffer = new CircularBuffer<int>(5);
var array = new [] { 1, 2, 3, -1, 0 };
for(var i = 0; i < 3; i++)
{
buffer.Add(array[i]);
}
var copy = new int[5];
copy[3] = -1;
buffer.CopyTo(copy, 0);
CollectionAssert.AreEqual(array, copy);
}
示例13: Add_HugeNumber_WorksCorrectly
[Ignore] // This test runs for ages, only run if needed
public void Add_HugeNumber_WorksCorrectly()
{
var buffer = new CircularBuffer<long>(100000);
var random = new Random();
long lastValue = 0;
for (long i = 0; i < int.MaxValue + 1000L; i++)
{
lastValue++;
buffer.Add(lastValue);
}
long testValue = lastValue - buffer.Count + 1;
foreach (var item in buffer)
{
Assert.AreEqual(testValue, item);
testValue++;
}
}
示例14: Enumerate_Reset_ProperlyResets
public void Enumerate_Reset_ProperlyResets()
{
var buffer = new CircularBuffer<int>(3);
buffer.Add(1);
buffer.Add(2);
buffer.Add(3);
var en = buffer.GetEnumerator();
en.MoveNext();
Assert.AreEqual(1, en.Current);
en.MoveNext();
Assert.AreEqual(2, en.Current);
en.Reset();
en.MoveNext();
Assert.AreEqual(1, en.Current);
en.MoveNext();
Assert.AreEqual(2, en.Current);
}
示例15: ContainsDefaultInt_NotYetFull_ReturnsFalse
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);
}