Advertisement
Guest User

Moshe Binieli - TDD

a guest
Nov 14th, 2018
1,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using Stack;
  2. using NUnit.Framework;
  3.  
  4. namespace StackTests
  5. {
  6.     [TestFixture]
  7.     public class StackTest
  8.     {
  9.         [Test]
  10.         public void Creation()
  11.         {
  12.             Stack<int> s = new Stack<int>(3);
  13.             Assert.AreEqual(0, s.Size);
  14.         }
  15.  
  16.         [Test]
  17.         public void Push_Pop()
  18.         {
  19.             Stack<int> s = new Stack<int>(3);
  20.  
  21.             s.Push(1);
  22.             s.Push(2);
  23.             s.Push(3);
  24.             int value = s.Pop();
  25.  
  26.             Assert.AreEqual(3, value);
  27.             Assert.AreEqual(2, s.Size);
  28.         }
  29.  
  30.         [Test]
  31.         public void Too_Much_Pop()
  32.         {
  33.             Stack<int> s = new Stack<int>(3);
  34.             Assert.Throws<ExpenditureProhibitedException>(() => s.Pop());
  35.         }
  36.  
  37.         [Test]
  38.         public void Too_Much_Push()
  39.         {
  40.             Stack<int> s = new Stack<int>(3);
  41.             s.Push(1);
  42.             s.Push(2);
  43.             s.Push(3);
  44.             Assert.Throws<ExceededSizeException>(() => s.Push(4));
  45.         }
  46.  
  47.         [Test]
  48.         public void Peek_Exception()
  49.         {
  50.             Stack<int> s = new Stack<int>(3);
  51.             Assert.Throws<ExpenditureProhibitedException>(() => s.Peek());
  52.         }
  53.  
  54.         [Test]
  55.         public void Peek_Element()
  56.         {
  57.             Stack<int> s = new Stack<int>(3);
  58.  
  59.             s.Push(1);
  60.             s.Push(2);
  61.             int value = s.Peek();
  62.  
  63.             Assert.AreEqual(2, value);
  64.             Assert.AreEqual(2, s.Size);
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement