Chapter 2: Test-Driven Development in .NET - By Example

In this chapter, we ll demonstrate how to implement a Stack using Test-Driven Development (TDD). We have found that the best way to understand TDD is to see it practiced and follow along step by step. The following are the steps we used to build a Stack using this method.

The Task

The task is to implement an unbounded Stack , which is a data structure in which access is restricted to the most recently inserted item.


An unbounded Stack doesn t have to be presized, and you can insert an unlimited number of elements onto it.

The operations include Push , Pop , Top, and IsEmpty . The Push function inserts an element onto the top of the Stack. The Pop function removes the topmost element and returns it; the Top operation returns the topmost element but does not remove it from the Stack . The IsEmpty function returns true when there are no elements on the Stack . Figure 2-1 shows the Push operation in action, Figure 2-2 shows the Pop operation, and Figure 2-3 shows the Top operation.

click to expand
Figure 2-1: Push operation
click to expand
Figure 2-2: Pop operation
click to expand
Figure 2-3: Top operation

Test-Driven Development in Microsoft .NET
Test-Driven Development in Microsoft .NET (Microsoft Professional)
ISBN: 0735619484
EAN: 2147483647
Year: 2004
Pages: 85

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: