using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using MyLibrary; using System.Diagnostics; namespace Tests { [TestClass] public class StackTest { private Stack stack; public StackTest() { stack = new Stack(5); Console.WriteLine("vytvartim"); } [ClassInitialize] public static void ClassInit(TestContext ctx) { Trace.WriteLine("Class StackTest Initialized"); } [ClassCleanup] public static void ClassCleanUp() { Trace.WriteLine("Class StackTest Cleaned up"); } [TestInitialize] public void TestInit() { Trace.WriteLine("TEst Initialized"); } [TestCleanup] public void TestCleanUp() { Trace.WriteLine("TEst Cleaned Up"); } [TestMethod] public void Stack_UnderflowTest_ReturnsNull() { int? val = stack.Peek(); Assert.IsNull(val); int? val2 = stack.Pop(); Assert.IsNull(val2); } [TestMethod] public void Stack_PushAndPop_GetsSameVal() { stack.Push(33); int? val = stack.Pop(); Assert.AreEqual(val, 33); stack.Push(1); stack.Push(42); stack.Push(25); int? val2 = stack.Pop(); int? val3 = stack.Pop(); Assert.AreEqual(val2, 25); Assert.AreEqual(val3, 42); } [DataTestMethod] [DataRow(new [] {1, 2, 3, 4})] [DataRow(new[] { 88,66,22,5})] [DataRow(new[] { 88, 66,})] public void Stack_PushMore_GetsSameVal(int[] array) { foreach (int i in array) { stack.Push(i); } int[] res = new int[array.Length]; for (int i=0; i= data.Length) { ResizeDataStructure(); } data[nextPost] = number; return true; } private void ResizeDataStructure() { int[] nextData = new int[data.Length * resizeFactor]; data.CopyTo(nextData, 0); data = nextData; } private bool IsEmpty() { return head <= -1; } public void Print() { for (int i = Size() - 1; i >= 0; i--) { Console.Write(data[i]); Console.Write(", "); } Console.WriteLine(); } } using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using NUnit; using NUnit.Framework; [SetUpFixture] public class GlobalInit { [OneTimeSetUp] public void Set() { Debug.WriteLine("Global Setup"); } [OneTimeTearDown] public void TearDonw() { Debug.WriteLine("Global Teardown"); } } namespace TestProject1 { [SetUpFixture] public class Init { [OneTimeSetUp] public void Set() { Debug.WriteLine("Fixture Setup"); } [OneTimeTearDown] public void TearDonw() { Debug.WriteLine("Fixture Teardown"); } } } using NUnit.Framework; using NUnitLib; using System; using System.Diagnostics; namespace TestProject1 { public class Tests { private Stack stack; public Tests() { } [SetUp] public void Setup() { stack = new Stack(5); Debug.WriteLine("Test Setup"); } [TearDown] public void TearDown() { Debug.WriteLine("TestTearDown"); } [Test] public void Stack_UnderflowTest_ReturnsNull() { int? val = stack.Peek(); Assert.IsNull(val); int? val2 = stack.Pop(); Assert.IsNull(val2); } [Test] public void Stack_PushAndPop_GetsSameVal() { stack.Push(33); int? val = stack.Pop(); Assert.AreEqual(val, 33); stack.Push(1); stack.Push(42); stack.Push(25); int? val2 = stack.Pop(); int? val3 = stack.Pop(); Assert.AreEqual(val2, 25); Assert.AreEqual(val3, 42); } [TestCase(new[] { 1, 2, 3, 4 })] [TestCase(new[] { 88, 66, 22, 5 })] [TestCase(new[] { 88, 66, })] public void Stack_PushMore_GetsSameVal(int[] array) { foreach (int i in array) { stack.Push(i); } int[] res = new int[array.Length]; for (int i = 0; i < array.Length; i++) { res[i] = (int)stack.Pop(); } Array.Reverse(res); CollectionAssert.AreEqual(array, res); } } }