9
Tests unitaires
- #include "min.h"
- #include <stdlib.h>
- #include <stdio.h>
- #ifdef DEBUG
- int debug = 0; // 0 - off, 1 - on
- #endif
- #ifdef DEBUG
- #define ONDEBUG( expr ) do { if ( debug ) { expr; } } while ( 0 )
- #else
- #define ONDEBUG( expr )
- #endif
- int min( int x, int y ) {
- ONDEBUG( printf("min(%d, %d)\n", x, y); );
- return x < y ? x : y;
- }
- #if defined( STANDALONE )
- int main() {
- int a, b;
- printf("Enter 2 numbers at the prompt or ^Z|^D.\n");
- for( ;; ) {
- printf("\n? ");
- switch( scanf( "%d %d", &a, &b ) ) {
- case -1:
- exit(0);
- case 2:
- printf(" = %d", min( a, b));
- break;
- default:
- scanf( "%*s" ); /* swallow bad input */
- break;
- }
- }
- exit(0);
- }
- #endif
- #if !defined( _MIN_H )
- #define _MIN_H
- int min( int, int );
- #endif
Commentaires