Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Stack_v2.c, implementing a more advanced stack */
- /* Module Test function */
- void Test(void) {
- const uint8_t values[10] = {1,2,3,4,5,6,7,8,9,10};
- int i;
- uint8_t val;
- StackError_t res;
- res = Init(); /* initialize stack */
- if (res!=STACK_NO_ERROR) {
- for (;;) {}/* error */
- }
- /* stack is empty here, test it */
- if (!isEmpty()) {
- for (;;) {}/* error */
- }
- /* push values on stack */
- for(i=0;i<sizeof(values)/sizeof(values[0]);i++) {
- res = Push(values[i]);
- if (res!=STACK_NO_ERROR) {
- for (;;) {}/* error */
- }
- }
- /* stack is full here, test it */
- if (!isFull()) {
- for (;;) {}/* error */
- }
- /* stack must be full here: test error case */
- res = Push(123);
- if (res!=STACK_OVERFLOW_ERROR) {
- for(;;){} /* error! */
- }
- /* get elements from the stack */
- for(i=sizeof(values)/sizeof(values[0])-1;i>=0;i--) {
- res = Peek(&val);
- if (res!=STACK_NO_ERROR || val!=values[i]) {
- for(;;){} /* error! */
- }
- res = Pop(&val);
- if (res!=STACK_NO_ERROR || val!=values[i]) {
- for(;;){} /* error! */
- }
- }
- /* stack is empty here, test it */
- if (!isEmpty()) {
- for (;;) {}/* error */
- }
- /* test error cases: stack is empty here */
- res = Peek(&val);
- if (res!=STACK_UNDERFLOW_ERROR) {
- for(;;){} /* error! */
- }
- res = Pop(&val);
- if (res!=STACK_UNDERFLOW_ERROR) {
- for(;;){} /* error! */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement