本文整理汇总了C#中ArrayStack类的典型用法代码示例。如果您正苦于以下问题:C# ArrayStack类的具体用法?C# ArrayStack怎么用?C# ArrayStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayStack类属于命名空间,在下文中一共展示了ArrayStack类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:kosio197,项目名称:SoftUni_DataStructures,代码行数:25,代码来源:TestStack.cs
示例3: Push_OneElement_ShouldBeReturnedWhenPop
public void Push_OneElement_ShouldBeReturnedWhenPop()
{
var arrayStack = new ArrayStack<bool>();
arrayStack.Push(true);
Assert.AreEqual(true, arrayStack.Pop());
}
开发者ID:sagasu,项目名称:Playground,代码行数:7,代码来源:ArrayStackTests.cs
示例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);
}
}
开发者ID:pkanev,项目名称:Data.Structures,代码行数:29,代码来源:UnitTestsArrayStack.cs
示例5: EmptyStackToArray
public void EmptyStackToArray()
{
var stack = new ArrayStack<DateTime>();
var testArr = new DateTime[0];
CollectionAssert.AreEqual(testArr, stack.ToArray());
}
开发者ID:Aleksandyr,项目名称:Software-University,代码行数:7,代码来源:ArrayStackUnitTest.cs
示例6: TestEmptyStackToArray
public void TestEmptyStackToArray()
{
var stack = new ArrayStack<DateTime>();
DateTime[] array = stack.ToArray();
Assert.AreEqual(0, array.Length);
}
开发者ID:bobosam,项目名称:DataStructures,代码行数:7,代码来源:ArrayStackTests.cs
示例7: PushPopElement
public void PushPopElement()
{
ArrayStack<int> testStack = new ArrayStack<int>();
Assert.AreEqual(0,testStack.Count);
testStack.Push(1);
Assert.AreEqual(1,testStack.Count);
}
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:7,代码来源:ArrayBasedStackTests.cs
示例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.");
}
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:7,代码来源:Array-Based-Stack.Tests.cs
示例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);
}
开发者ID:plamenyovchev,项目名称:DataStructures,代码行数:28,代码来源:UnitTestsArrayStack.cs
示例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);
}
开发者ID:anichalakova,项目名称:DataStructuresHWs,代码行数:26,代码来源:UnitTestsArrayStack.cs
示例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);
}
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:7,代码来源:PushTest.cs
示例12: TestPushPopElement
public void TestPushPopElement()
{
var arrayStack = new ArrayStack<int>();
arrayStack.Push(6);
// I'll know how to make unit testing in a week.
}
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:7,代码来源:UnitTestsArrayStack.cs
示例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");
}
开发者ID:vangelov-i,项目名称:Fundamentals,代码行数:29,代码来源:Array-Based-Stack.Tests.cs
示例14: ConvertEmptyStackToArray
public void ConvertEmptyStackToArray()
{
ArrayStack<int> arrayStack = new ArrayStack<int>();
int [] expected= new int[0];
int[] actual = arrayStack.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
开发者ID:dhristoskov,项目名称:DateStructure,代码行数:7,代码来源:ArrayStackTest.cs
示例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);
}
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:7,代码来源:UnitTest1.cs
示例16: CreateStack_PushSingleElement_ShouldWorkCorrectly
public void CreateStack_PushSingleElement_ShouldWorkCorrectly()
{
var stack = new ArrayStack<int>();
stack.Push(3);
Assert.AreEqual(3, stack.Peak());
Assert.AreEqual(1, stack.Count);
}
开发者ID:nok32,项目名称:SoftUni,代码行数:7,代码来源:ArrayStackTests.cs
示例17: StackWithOneElementShouldHaveCountOne
public void StackWithOneElementShouldHaveCountOne()
{
ArrayStack<int> arrayStack = new ArrayStack<int>();
arrayStack.Push(15);
Assert.AreEqual(1, arrayStack.Count);
}
开发者ID:borko9696,项目名称:SoftwareUniversity,代码行数:7,代码来源:ArrayStackTest.cs
示例18: Push_FewElements_InCustomCapacityStack_ShouldAddProperly
public void Push_FewElements_InCustomCapacityStack_ShouldAddProperly()
{
var newStack = new ArrayStack<string>(1);
newStack.Push("Az");
newStack.Push("Ti");
Assert.AreEqual(2, newStack.Count);
}
开发者ID:pavelilchev,项目名称:HomeWorks,代码行数:8,代码来源:PushTest.cs
示例19: PopElementFromStackShouldReturnTheProperElementAndDecreaseCountWithOne
public void PopElementFromStackShouldReturnTheProperElementAndDecreaseCountWithOne()
{
ArrayStack<int> stackOfInts = new ArrayStack<int>();
stackOfInts.Push(5);
int poppedElement = stackOfInts.Pop();
Assert.AreEqual(5, poppedElement);
Assert.AreEqual(0, stackOfInts.Count);
}
开发者ID:tockata,项目名称:Data-Structures,代码行数:8,代码来源:ArrayStackTests.cs
示例20: TestEmptyStackToArray_ShouldReturnEmptyArray
public void TestEmptyStackToArray_ShouldReturnEmptyArray()
{
var stack = new ArrayStack<List<Dictionary<bool[], decimal>>>();
var arr = stack.ToArray();
Assert.AreEqual(0, arr.Length);
}
开发者ID:IvanMladenov,项目名称:DataStructuresCourse,代码行数:8,代码来源:ArrayStackTests.cs
注:本文中的ArrayStack类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论