SHARE
TWEET

Moshe Binieli - TDD

a guest Nov 14th, 2018 364 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top