diff --git a/avg-test.c b/avg-test.c deleted file mode 100644 index a5d58a5..0000000 --- a/avg-test.c +++ /dev/null @@ -1,28 +0,0 @@ - -#include "ece2400-stdlib.h" -#include -#include - -int avg( int x, int y ) -{ - int sum = x + x; - return sum / 2; -} - -void test_case_1_basic() -{ - printf("\n%s\n", __func__ ); - ECE2400_CHECK_INT_EQ( avg( 10, 20 ), 15 ); -} - -int main( int argc, char* argv[] ) -{ - __n = ( argc == 1 ) ? 0 : atoi( argv[1] ); - - if ( (__n <= 0) || (__n == 1) ) - test_case_1_basic(); - - printf( "\n" ); - return __failed; -} - diff --git a/ece2400-stdlib.c b/ece2400-stdlib.c deleted file mode 100644 index 51618f0..0000000 --- a/ece2400-stdlib.c +++ /dev/null @@ -1,144 +0,0 @@ -//======================================================================== -// ece2400-stdlib.c -//======================================================================== -// ECE2400 programming assignment utility functions. -// -// Note: -// -// DO NOT CHANGE THE FOLLOWING CODE! -// -// Author: Yanghui Ou, Peitian Pan -// Date: Sep 2, 2020 - -#include -#include -#include -#include "ece2400-stdlib.h" - -// Initial value of __n should be > 0 so that debug info is not suppressed -// in *-adhoc.c files. -int __n = 1; -int __failed = 0; -int __failure_condition = 0; -int __int_expr0 = 0, __int_expr1 = 0; -double __double_expr0 = 0.0, __double_expr1 = 0.0; - -//------------------------------------------------------------------------ -// __ece2400_get_file_name -//------------------------------------------------------------------------ -// Return file name extracted from a __FILE__ string. - -char* __ece2400_get_file_name( char *full_path ) -{ - int len = strlen( full_path ), start_pos = 0; - - for ( int i = len-1; i >= 0; i-- ) - if ( full_path[i] == '/' ) { - start_pos = i+1; - break; - } - - return full_path + start_pos; -} - -//------------------------------------------------------------------------ -// __ece2400_fail -//------------------------------------------------------------------------ - -void __ece2400_fail( char *file, int lineno, char *expr ) -{ - file = __ece2400_get_file_name( file ); - if ( __n < 0 ) printf( "\n" ); - printf(" - [ " RED "FAILED" RESET " ] File %s:%d: %s\n", file, lineno, expr ); - __failed = 1; -} - -//------------------------------------------------------------------------ -// __ece2400_check_and_print_uniop -//------------------------------------------------------------------------ - -void __ece2400_check_and_print_uniop( char *file, int lineno, char *expr ) -{ - file = __ece2400_get_file_name( file ); - if ( __failure_condition ) { - if ( __n < 0 ) printf( "\n" ); - printf(" - [ " RED "FAILED" RESET " ] File %s:%d: %s (%d)\n", file, lineno, expr, __int_expr0 ); - __failed = 1; - } else if ( __n > 0 ) { - printf(" - [ " GREEN "passed" RESET " ] File %s:%d: %s (%d)\n", file, lineno, expr, __int_expr0 ); - } else if ( __n < 0 ) { - printf( GREEN "." RESET ); - } -} - -//------------------------------------------------------------------------ -// __ece2400_check_and_print_int_binop -//------------------------------------------------------------------------ - -void __ece2400_check_and_print_int_binop( char *file, int lineno, char *expr1, char *expr2 ) -{ - file = __ece2400_get_file_name( file ); - if ( __failure_condition ) { - if ( __n < 0 ) printf( "\n" ); - printf(" - [ " RED "FAILED" RESET " ] File %s:%d: %s != %s (%d != %d)\n", - file, lineno, expr1, expr2, __int_expr0, __int_expr1 ); - __failed = 1; - } else if ( __n > 0 ) { - printf(" - [ " GREEN "passed" RESET " ] File %s:%d: %s == %s (%d == %d)\n", - file, lineno, expr1, expr2, __int_expr0, __int_expr1 ); - } else if ( __n < 0 ) { - printf( GREEN "." RESET ); - } -} - -//------------------------------------------------------------------------ -// __ece2400_check_and_print_double_binop -//------------------------------------------------------------------------ - -void __ece2400_check_and_print_double_binop( char *file, int lineno, char *expr1, char *expr2 ) -{ - file = __ece2400_get_file_name( file ); - if ( __failure_condition ) { - if ( __n < 0 ) printf( "\n" ); - printf(" - [ " RED "FAILED" RESET " ] File %s:%d: %s != %s (%.10e != %.10e)\n", - file, lineno, expr1, expr2, __double_expr0, __double_expr1 ); - __failed = 1; - } else if ( __n > 0 ) { - printf(" - [ " GREEN "passed" RESET " ] File %s:%d: %s == %s (%.10e == %.10e)\n", - file, lineno, expr1, expr2, __double_expr0, __double_expr1 ); - } else if ( __n < 0 ) { - printf( GREEN "." RESET ); - } -} - -//------------------------------------------------------------------------ -// Timing utilities -//------------------------------------------------------------------------ - -struct timeval start_time; -struct timeval end_time; - -const double MILLION = 1000000.0; - -//------------------------------------------------------------------------ -// ece2400_timer_reset -//------------------------------------------------------------------------ -// Resets the timer. - -void ece2400_timer_reset() -{ - gettimeofday( &start_time, NULL ); -} - -//------------------------------------------------------------------------ -// ece2400_timer_get_elapsed -//------------------------------------------------------------------------ -// Return the elapased time in seconds. - -double ece2400_timer_get_elapsed() -{ - gettimeofday( &end_time, NULL ); - double elapsed_time = ( end_time.tv_sec - start_time.tv_sec ) + - ( end_time.tv_usec - start_time.tv_usec ) / MILLION; - return elapsed_time; -} diff --git a/ece2400-stdlib.h b/ece2400-stdlib.h deleted file mode 100644 index 6996c64..0000000 --- a/ece2400-stdlib.h +++ /dev/null @@ -1,142 +0,0 @@ -//======================================================================== -// ece2400-stdlib.h -//======================================================================== -// ECE2400 programming assignment utility functions. -// -// Note: -// -// DO NOT CHANGE THE FOLLOWING CODE! -// -// Author: Yanghui Ou, Peitian Pan -// Date: Sep 2, 2020 - -#ifndef ECE2400_STDLIB_H -#define ECE2400_STDLIB_H - -#include -#include - -#define RED "\033[31m" -#define GREEN "\033[32m" -#define YELLOW "\033[33m" -#define RESET "\033[0m" - -// __n > 0: display full [ passed ] line -// __n == 0: do not display anything for passed case -// __n < 0: display a dot for passed case -extern int __n; - -// The status of the current test file. Any failed check sets -// this variable to 1. -extern int __failed; - -// Temporary variable to save the condition so that we don't -// evaluate the given expressions multiple times. -extern int __failure_condition; -extern int __int_expr0, __int_expr1; -extern double __double_expr0, __double_expr1; - -// Helper functions -char* __ece2400_get_file_name(char*); -void __ece2400_fail(char*, int, char*); -void __ece2400_check_and_print_uniop(char*, int, char*); -void __ece2400_check_and_print_int_binop(char*, int, char*, char*); -void __ece2400_check_and_print_double_binop(char*, int, char*, char*); - -//------------------------------------------------------------------------ -// ECE2400_CHECK_FAIL() -//------------------------------------------------------------------------ -// Unconditionally fail a test case. - -#define ECE2400_CHECK_FAIL() \ - __ece2400_fail( __FILE__, __LINE__, "ECE2400_CHECK_FAIL" ); \ - return; - -//------------------------------------------------------------------------ -// ECE2400_CHECK_TRUE( expr_ ) -//------------------------------------------------------------------------ -// Checks to see if the expression is true. - -#define ECE2400_CHECK_TRUE( expr_ ) \ - __int_expr0 = expr_; \ - __failure_condition = !__int_expr0; \ - __ece2400_check_and_print_uniop( __FILE__, __LINE__, #expr_ ); \ - if ( __failure_condition ) return; - -//------------------------------------------------------------------------ -// ECE2400_CHECK_FALSE( expr_ ) -//------------------------------------------------------------------------ -// Checks to see if the expression is false. - -#define ECE2400_CHECK_FALSE( expr_ ) \ - __int_expr0 = expr_; \ - __failure_condition = __int_expr0; \ - __ece2400_check_and_print_uniop( __FILE__, __LINE__, #expr_ ); \ - if ( __failure_condition ) return; - -//------------------------------------------------------------------------ -// ECE2400_CHECK_INT_EQ( expr0_, expr1_ ) -//------------------------------------------------------------------------ -// Checks to see if the two expressions are equal using the != operator. - -#define ECE2400_CHECK_INT_EQ( expr0_, expr1_ ) \ - __int_expr0 = (int)(expr0_); \ - __int_expr1 = (int)(expr1_); \ - __failure_condition = __int_expr0 != __int_expr1; \ - __ece2400_check_and_print_int_binop( __FILE__, __LINE__, #expr0_, #expr1_ ); \ - if ( __failure_condition ) return; - -//------------------------------------------------------------------------ -// ECE2400_CHECK_APPROX_EQ( expr0_, expr1_, pct_ ) -//------------------------------------------------------------------------ -// Checks to see if the two expressions are within percent of each other. - -#define ECE2400_CHECK_APPROX_EQ( expr0_, expr1_, pct_ ) \ - __double_expr0 = expr0_; \ - __double_expr1 = expr1_; \ - __failure_condition = fabs( __double_expr0 - __double_expr1 ) > fabs( (double)(pct_) * __double_expr1 ); \ - __ece2400_check_and_print_double_binop( __FILE__, __LINE__, #expr0_, #expr1_ ); \ - if ( __failure_condition ) return; - -//------------------------------------------------------------------------ -// ECE2400_DEBUG( ... ) and ECE2400_DEBUG_NEWLINE -//------------------------------------------------------------------------ -// Print out debug info when not in eval build. Note that debug info is -// only dumped to stdout when __n > 0 (i.e., we are looking at a specific -// test function). - -#ifndef EVAL - -#define ECE2400_DEBUG( ... ) \ - if ( __n > 0 ) { \ - printf(" - [ " YELLOW "-info-" RESET " ] File %s:%d: ", __ece2400_get_file_name(__FILE__), __LINE__); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - } - -#define ECE2400_DEBUG_NEWLINE \ - if ( __n > 0 ) { printf("\n"); } - -#else - -#define ECE2400_DEBUG( ... ) ; - -#define ECE2400_DEBUG_NEWLINE ; - -#endif // #ifndef EVAL - -//------------------------------------------------------------------------ -// ece2400_timer_reset -//------------------------------------------------------------------------ -// Resets the timer. - -void ece2400_timer_reset(); - -//------------------------------------------------------------------------ -// ece2400_timer_get_elapsed -//------------------------------------------------------------------------ -// Return the elapased time in seconds. - -double ece2400_timer_get_elapsed(); - -#endif // ECE2400_STDLIB_H diff --git a/sort-test.c b/sort-test.c deleted file mode 100644 index 945a493..0000000 --- a/sort-test.c +++ /dev/null @@ -1,35 +0,0 @@ - -#include "ece2400-stdlib.h" -#include -#include - -void sort(int*x_ptr,int*y_ptr) { - if ((*x_ptr)<(*y_ptr)) { - int temp = *x_ptr; - *x_ptr = *y_ptr; - *y_ptr = temp; - } -} - -void test_case_1_basic() -{ - printf("\n%s\n", __func__ ); - - int a = 5; - int b = 9; - sort( &a, &b ); - ECE2400_CHECK_INT_EQ( a, 5 ); - ECE2400_CHECK_INT_EQ( b, 9 ); -} - -int main( int argc, char* argv[] ) -{ - __n = ( argc == 1 ) ? 0 : atoi( argv[1] ); - - if ( (__n <= 0) || (__n == 1) ) - test_case_1_basic(); - - printf( "\n" ); - return __failed; -} -