本文整理汇总了C#中ArrayStack类的典型用法代码示例。如果您正苦于以下问题:C# ArrayStack类的具体用法?C# ArrayStack怎么用?C# ArrayStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayStack类属于命名空间,在下文中一共展示了ArrayStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PushAndPop_StackWith1000Elemnts_ShouldTestTheAutoGrowFunctionality
public void PushAndPop_StackWith1000Elemnts_ShouldTestTheAutoGrowFunctionality()
{
//Arrange
var stack = new ArrayStack<string>();
int i = 0;
//Assert
Assert.AreEqual(0, stack.Count);
while(i != 1000)
{
//Act
i++;
stack.Push(i.ToString());
//Assert
Assert.AreEqual(i, stack.Count);
}
while (i != 0)
{
//Act
i--;
string lastElement = stack.Pop();
//Assert
Assert.AreEqual(i, stack.Count);
Assert.AreEqual((i + 1).ToString(), lastElement);
}
}
开发者ID:nadiahristova,项目名称:Data-Structures-Algorithms-and-Complexity,代码行数:30,代码来源:UnitTestArrayStack.cs
示例2: Test_Push_Pop
public void Test_Push_Pop()
{
ArrayStack<int> roo = new ArrayStack<int>();
Assert.AreEqual(0,roo.Count);
roo.Push(9);
Assert.AreEqual(1,roo.Count);
Assert.AreEqual(9,roo.Pop());
Assert.AreEqual(0,roo.Count);
ArrayStack<string> testPush = new ArrayStack<string>();
Assert.AreEqual(0, testPush.Count);
for (int i = 1; i <= 1000; i++)
{
testPush.Push("as"+i);
Assert.AreEqual(i, testPush.Count);
}
for (int i = 1000; i >= 1; i--)
{
Assert.AreEqual("as"+i, testPush.Pop());
Assert.AreEqual(i - 1, testPush.Count);
}
}
示例3: Push_OneElement_ShouldBeReturnedWhenPop
public void Push_OneElement_ShouldBeReturnedWhenPop()
{
var arrayStack = new ArrayStack<bool>();
arrayStack.Push(true);
Assert.AreEqual(true, arrayStack.Pop());
}
示例4: ArrayStack_PushPopManyChunks_ShouldWorkCorrectly
public void ArrayStack_PushPopManyChunks_ShouldWorkCorrectly()
{
// Arrange
var stack = new ArrayStack<int>();
int chunks = 100;
// Act & Assert in a loop
int value = 1;
for (int i = 0; i < chunks; i++)
{
Assert.AreEqual(0, stack.Count);
var chunkSize = i + 1;
for (int counter = 0; counter < chunkSize; counter++)
{
Assert.AreEqual(value - 1, stack.Count);
stack.Push(value);
Assert.AreEqual(value, stack.Count);
value++;
}
for (int counter = 0; counter < chunkSize; counter++)
{
value--;
Assert.AreEqual(value, stack.Count);
stack.Pop();
Assert.AreEqual(value - 1, stack.Count);
}
Assert.AreEqual(0, stack.Count);
}
}
示例5: EmptyStackToArray
public void EmptyStackToArray()
{
var stack = new ArrayStack<DateTime>();
var testArr = new DateTime[0];
CollectionAssert.AreEqual(testArr, stack.ToArray());
}
示例6: TestEmptyStackToArray
public void TestEmptyStackToArray()
{
var stack = new ArrayStack<DateTime>();
DateTime[] array = stack.ToArray();
Assert.AreEqual(0, array.Length);
}
示例7: PushPopElement
public void PushPopElement()
{
ArrayStack<int> testStack = new ArrayStack<int>();
Assert.AreEqual(0,testStack.Count);
testStack.Push(1);
Assert.AreEqual(1,testStack.Count);
}
示例8: EmptyStackToArray_ShouldReturnEmptyArray
public void EmptyStackToArray_ShouldReturnEmptyArray()
{
var stack = new ArrayStack<DateTime>();
var actual = stack.ToArray().Length;
Assert.AreEqual(0, actual, "Array is not empty.");
}
示例9: PushAndPopRepeat1000Times
public void PushAndPopRepeat1000Times()
{
// Arrange
ArrayStack<string> stack = new ArrayStack<string>();
var count = 0;
// Assert
Assert.AreEqual(count, stack.Count);
// Act
for (int i = 0; i < 1000; i++)
{
stack.Push("Plamen");
}
// Assert
Assert.AreEqual(1000, stack.Count);
// Act
var poppedElement = string.Empty;
for (int i = 0; i < 1000; i++)
{
poppedElement = stack.Pop();
}
Assert.AreEqual(poppedElement, "Plamen");
Assert.AreEqual(count, stack.Count);
}
示例10: PushAndPopWithInitialCapacity1ShouldWorkCorrectly
public void PushAndPopWithInitialCapacity1ShouldWorkCorrectly()
{
//Arrange
var stack = new ArrayStack<int>(1);
//Assert
Assert.AreEqual(0, stack.Count);
//Act
stack.Push(1);
//Assert
Assert.AreEqual(1, stack.Count);
//Act
stack.Push(2);
//Assert
Assert.AreEqual(2, stack.Count);
//Act
var element = stack.Pop();
//Assert
Assert.AreEqual(2, element);
Assert.AreEqual(1, stack.Count);
//Act
element = stack.Pop();
//Assert
Assert.AreEqual(1, element);
Assert.AreEqual(0, stack.Count);
}
示例11: Push_OneElement_InCustomCapacityStack_ShouldAddProperly
public void Push_OneElement_InCustomCapacityStack_ShouldAddProperly()
{
var newStack = new ArrayStack<string>(1);
newStack.Push("ha");
Assert.AreEqual(1, newStack.Count);
}
示例12: TestPushPopElement
public void TestPushPopElement()
{
var arrayStack = new ArrayStack<int>();
arrayStack.Push(6);
// I'll know how to make unit testing in a week.
}
示例13: PushPop100Elements_CountShouldBeCorrect
public void PushPop100Elements_CountShouldBeCorrect()
{
var stack = new ArrayStack<string>();
var items = new List<string>();
Assert.AreEqual(0, stack.Count, "Count is not 0.");
for (int i = 0; i < 1000; i++)
{
string currentElement = i.ToString();
items.Add((999 - i).ToString());
stack.Push(currentElement);
Assert.AreEqual(i + 1, stack.Count, $"Count is not {i + 1}.");
}
Assert.AreEqual(1000, stack.Count, "Count is not 1000.");
for (int i = 0; i < 1000; i++)
{
string poppedElement = stack.Pop();
string expectedElement = items[i];
Assert.AreEqual(expectedElement, poppedElement, $"Popped element is not {expectedElement}");
Assert.AreEqual(999 - i, stack.Count, $"Count is not {999 - i}.");
}
Assert.AreEqual(0, stack.Count, "Count is not 0");
}
示例14: ConvertEmptyStackToArray
public void ConvertEmptyStackToArray()
{
ArrayStack<int> arrayStack = new ArrayStack<int>();
int [] expected= new int[0];
int[] actual = arrayStack.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
示例15: TestEmptyStackToArray_ShouldReturnEmptyArray
public void TestEmptyStackToArray_ShouldReturnEmptyArray()
{
var stack = new ArrayStack<DateTime>();
var array = stack.ToArray();
var expected = new DateTime[0];
CollectionAssert.AreEqual(expected, array);
}