Skip to content

Instantly share code, notes, and snippets.

@rsotto
Last active November 28, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsotto/9f607d9b76a910caefc4211c94340c7e to your computer and use it in GitHub Desktop.
Save rsotto/9f607d9b76a910caefc4211c94340c7e to your computer and use it in GitHub Desktop.
[TestClass()]
public class MyStackTests
{
[TestMethod()]
public void ConstructorTest()
{
var myStack = new MyStack<int>();
Assert.IsTrue(myStack.Size == 0, "Expecting stack size to be 0 but is not.");
Assert.IsTrue(myStack.IsEmpty, "Expecting stack to be empty but is not.");
}
// ...
[TestMethod()]
public void PopTest()
{
var myStack = new MyStack<double>();
myStack.Push(1.5);
myStack.Push(3.2);
Assert.AreEqual(3.2, myStack.Pop(), "Expecting popped element to be 3.2 but is not.");
Assert.AreEqual(1.5, myStack.Pop(), "Expecting popped element to be 1.5 but is not.");
}
[TestMethod()]
public void PopIsEmptyTest()
{
var myStack = new MyStack<int>();
Assert.ThrowsException<InvalidOperationException>(delegate () { myStack.Pop(); },
"Did not throw InvalidOperationException when Pop() is called when stack is empty.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment