Class Kata "Stack"

Implement the abstract data type Stack.

The stack as a data structure is a first-in, last-out storage. Elements that are placed on the stack are returned from it in reverse order. The stack interface to be implemented is as follows:

public interface IStack
{
    void Push(TElement element);

    TElement Pop();
}

The data structure is to be implemented as a generic type. It has the two operations Push and Pop. With Push an element is placed on the stack. Pop returns the top element of the stack and removes it from the stack. If Pop is applied to an empty stack, a InvalidOperationException Exception triggered.

The following table shows how a stack behaves:

Class Kata Stack - Clean Code Developer Akademie

Variation

Do not use the pop operation when automatically testing the push operation. Similarly, do not use the push operation when testing the pop operation.

Of course, there should also be tests that demonstrate how push and pop work together. In order to obtain meaningful test results, it is useful to isolate the tests of the individual operations from each other. If the test for the push operation fails, but the test for pop is successful, this tells us more precisely where the problem lies. In this way, it is also possible to implement the two operations in any order and independently of each other.

en_USEnglish