public void FullStackArrayTests0() { var stackArray = new StackArray <int>(5); for (var i = 0; i < 5; i++) { Assert.True(stackArray.Count == i); stackArray.Push(i * 2); } Assert.True(stackArray.IsFull); Assert.False(stackArray.IsEmpty); Assert.Throws <InvalidOperationException>(() => stackArray.Push(10)); Assert.Throws <InvalidOperationException>(() => stackArray.Push(12)); Assert.True(stackArray.Peek() == 8); Assert.True(stackArray.Pop() == 8); Assert.True(stackArray.Count == 4); Assert.True(stackArray.Length == 5); Assert.False(stackArray.IsFull); Assert.False(stackArray.IsEmpty); stackArray.Push(8); Assert.True(stackArray.Peek() == 8); Assert.Throws <InvalidOperationException>(() => stackArray.Push(10)); Assert.True(stackArray.IsFull); Assert.False(stackArray.IsEmpty); Assert.True(stackArray.Length == 5); Assert.True(stackArray.Count == 5); }
[TestMethod] //Тест заполнения стека public void PushTest() { int n = 3; StackArray<object> data = new StackArray<object>(n); data.Push(8); data.Push(6); data.Push(10); }
[TestMethod] //Тест заполнения стека public void PushTest() { int n = 3; StackArray <object> data = new StackArray <object>(n); data.Push(8); data.Push(6); data.Push(10); }
[TestMethod] //IEnumerable public void EnumerableTest() { int n = 3; StackArray <object> data = new StackArray <object>(n); data.Push(8); data.Push(6); data.Push(10); data.GetEnumerator(); }
[TestMethod] //IDisposable public void DisposeTest() { int n = 3; StackArray <object> data = new StackArray <object>(n); data.Push(8); data.Push(6); data.Push(10); data.Dispose(); }
[TestMethod] //IEnumerable public void EnumerableTest() { int n = 3; StackArray<object> data = new StackArray<object>(n); data.Push(8); data.Push(6); data.Push(10); data.GetEnumerator(); }
[TestMethod] //IDisposable public void DisposeTest() { int n = 3; StackArray<object> data = new StackArray<object>(n); data.Push(8); data.Push(6); data.Push(10); data.Dispose(); }
public void PopTestWithTwoElemets() { stack.Push(666); stack.Push(-666); Assert.AreEqual(-666, stack.Pop()); Assert.AreEqual(666, stack.Pop()); }
public void TestStack() { var stack = new StackArray <int>(); stack.Push(10); stack.Push(20); Assert.Equal(2, stack.Count); Assert.False(stack.IsEmpty); Assert.Equal(20, stack.Pop()); Assert.Equal(10, stack.Pop()); Assert.True(stack.IsEmpty); }
public void PushWithResizeWorkCorrect() { for (var i = 0; i < 1000; ++i) { stack.Push(1); } }
public static int[] CalculateSpan(int[] Input) { int len = Input.Length; int[] Span = new int[len]; //Span[0] = 0; IStack stk = new StackArray(len); //stk.Push(0); for (int i = 0; i < len; i++) { if (i == 0) { Span[0] = 0; stk.Push(0); } else { if (Input[i] < Input[i - 1]) { Span[i] = 1; stk.Push(i); } else { while (!stk.IsEmpty() && Input[stk.Top()] < Input[i]) { stk.Pop(); } if (stk.IsEmpty()) { Span[i] = 0; stk.Push(i); } else { Span[i] = i - stk.Top(); stk.Push(i); } } } } return(Span); }
// StackArray [Benchmark] public void StackArray_Push() { IStack <Person> stack = new StackArray <Person>(); foreach (Person person in RandomTestData) { stack.Push(person); } }
[Benchmark] public void StackArray_PushWithCapacity() { IStack <Person> stack = new StackArray <Person>(RandomTestData.Length); foreach (Person person in RandomTestData) { stack.Push(person); } }
public void Add() { IStack <Person> stack = new StackArray <Person>(); foreach (Person person in RandomTestData) { stack.Push(person); } }
public void PushElements() { var stack = new StackArray <int>(); for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } }
public void PushPop() { var stack = new StackArray <int>(); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); stack.Push(5); Assert.AreEqual("54321", stack.GetValues()); stack.Pop(); Assert.AreEqual("4321", stack.GetValues()); stack.Pop(); Assert.AreEqual("321", stack.GetValues()); }
public void StackSizeIncreases() { var stack = new StackArray <int>(); for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } Assert.AreEqual(MAX_SIZE, stack.Size()); }
public void PushWithCapacity() { IStack <int> stack = new StackArray <int>(PushCount); int pushCount = PushCount; for (int i = 0; i < pushCount; i++) { stack.Push(i); } }
public void ResizeTest() { var stack = new StackArray(); for (var i = 0; i < 1000; ++i) { stack.Push(i); } Assert.AreEqual(999, stack.Pop()); }
public void PushTest() { Stack stack = new StackArray(3); stack.Push(1); stack.Push(2); stack.Push(3); stack.Push(4); int?[] stackArray = getArray(stack); Assert.IsNotNull(stackArray); Assert.AreEqual(6, stackArray.Length); Assert.AreEqual(1, stackArray[0]); Assert.AreEqual(2, stackArray[1]); Assert.AreEqual(3, stackArray[2]); Assert.AreEqual(4, stackArray[3]); Assert.IsNull(stackArray[4]); Assert.IsNull(stackArray[5]); }
[TestMethod] public void Push_Pop_Testing() { void Test <T>(T[] values) { Towel.Sort.Shuffle(values); IStack <T> stack = new StackArray <T>(); values.Stepper(x => stack.Push(x)); Array.Reverse(values); values.Stepper(x => x.Equals(stack.Pop())); }
public void PopReturnsValue() { var stack = new StackArray <int>(); for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } for (int i = MAX_SIZE - 1; i > 0; i--) { Assert.AreEqual(i, stack.Pop()); } }
public override int Pop() { while (!IsEmpty()) { _stackArray.Push(base.Pop()); } int ret = _stackArray.Pop(); while (!_stackArray.IsEmpty()) { Push(_stackArray.Pop()); } return(ret); }
public void PopTest() { Stack stack = new StackArray(3); stack.Push(1); var output = stack.Pop(); Assert.AreEqual(1, output); output = stack.Pop(); Assert.IsNull(output); stack.Push(2); stack.Push(5); stack.Push(7); output = stack.Pop(); Assert.AreEqual(7, output); output = stack.Pop(); Assert.AreEqual(5, output); output = stack.Pop(); Assert.AreEqual(2, output); output = stack.Pop(); Assert.IsNull(output); }
public void StackSizeDecreases() { var stack = new StackArray <int>(); for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } for (int i = MAX_SIZE; i > 0; i--) { stack.Pop(); } Assert.AreEqual(0, stack.Size()); }
public static bool IspisiStekObrnuto <T>(Stack <T> stack) { //posto mi vec ToString() ispisuje Top na kraju, sad ce ga ispisati prvog. Ovo nema smisla, jer ne mogu da procitam nista sem TOP na steku, pa moram da obrisem ceo stek i ponovo ga napravim. StackArray <T> tmp = new StackArray <T>((uint)stack.Size); int len = stack.Size; for (int i = 0; i < len; ++i) { tmp.Push(stack.Top); stack.Pop(); } Console.WriteLine(tmp); for (int i = 0; i < len; ++i) { stack.Push(tmp.Top); tmp.Pop(); } return(true); }
public void FullTest() { Stack stack = new StackArray(100); int testLength = 512; Random rnd = new Random(); int[] comparisonArray = new int[testLength]; for (int i = 0; i < testLength; i++) { int element = rnd.Next(0, 10000000); comparisonArray[comparisonArray.Length - i - 1] = element; stack.Push(element); } for (int i = 0; i < comparisonArray.Length; i++) { Assert.AreEqual(comparisonArray[i], stack.Peek()); Assert.AreEqual(comparisonArray[i], stack.Pop()); } }
public void PeekTest() { Stack stack = new StackArray(); stack.Push(5); var peek = stack.Peek(); Assert.IsNotNull(peek); Assert.AreEqual(5, peek); peek = stack.Peek(); Assert.IsNotNull(peek); Assert.AreEqual(5, peek); var pop = stack.Pop(); Assert.IsNotNull(pop); Assert.AreEqual(5, pop); peek = stack.Peek(); Assert.IsNull(peek); Assert.IsNull(stack.Pop()); }
static void Main(string[] args) { string inputLine; StackArray <int> stack = new StackArray <int>(); while ((inputLine = Console.ReadLine()) != "END") { string[] data = inputLine.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries); switch (data[0]) { case "Push": IEnumerable <int> elements = data.Skip(1).Select(int.Parse); stack.Push(elements); break; case "Pop": try { stack.Pop(); } catch (ArgumentException e) { Console.WriteLine(e.Message); } break; default: break; } } printStack(stack); printStack(stack); }
public void PushPop() { var stack = new StackArray <int>(); try { for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } for (int i = MAX_SIZE; i > 0; i--) { stack.Pop(); } } catch (InvalidOperationException) { Assert.Fail("Failed to pop all elements."); } }
/// <summary> /// Writes the current tag to the output. Inserts closing /// tags as necessary. /// </summary> private void HandleTag(HtmlTag tag) { if (tag.IsSelfClosingTag && tag.IsEndTag) { return; } if (tag.IsEndTag) { CloseBackToMatchingTag(tag.Name); return; } ProcessHandlers(tag.Name); xml.Append('<'); xml.Append(tag.Name); xml.Append(tag.AttributesPart); if (tag.IsSelfClosingTag) { if (xml[xml.Length - 1] == ' ') { xml.Length = xml.Length - 1; } xml.Append('/'); } else { openElements.Push(tag.Name); } xml.Append('>'); if (IsScriptCDataElement(tag.Name)) { SkipToEndOfScriptCData(tag.Name); } }
public void StackIsEmpty() { var stack = new StackArray <int>(); InvalidOperationException ex = new InvalidOperationException(); try { for (int i = 0; i < MAX_SIZE; i++) { stack.Push(i); } for (int i = 0; i < MAX_SIZE + 1; i++) { stack.Pop(); } } catch (InvalidOperationException e) { ex = e; } Assert.AreEqual("The Stack is empty.", ex.Message); }
public void Destroy(Bullet bullet) { stack.Push(bullet); bullet.gameObject.SetActive(false); bullet.transform.SetParent(transform, true); }