# include # include # include # include # include # include "l4lib.h" int main ( ); void i4_to_l4_test ( ); void i4_to_l4vec_test ( ); void l4_to_i4_test ( ); void l4_to_s_test ( ); void l4_uniform_test ( ); void l4_xor_test ( ); void l4mat_print_test ( ); void l4mat_print_some_test ( ); void l4mat_transpose_print_test ( ); void l4mat_transpose_print_some_test ( ); void l4mat_uniform_new_test ( ); void l4vec_next_test ( ); void l4vec_print_test ( ); void l4vec_uniform_new_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: l4lib_test() tests l4lib(). Licensing: This code is distributed under the GNU LGPL license. Modified: 01 August 2016 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "L4LIB_TEST\n" ); printf ( " C version\n" ); printf ( " Test the L4LIB library.\n" ); i4_to_l4_test ( ); i4_to_l4vec_test ( ); l4_to_i4_test ( ); l4_to_s_test ( ); l4_uniform_test ( ); l4_xor_test ( ); l4mat_print_test ( ); l4mat_print_some_test ( ); l4mat_transpose_print_test ( ); l4mat_transpose_print_some_test ( ); l4mat_uniform_new_test ( ); l4vec_next_test ( ); l4vec_print_test ( ); l4vec_uniform_new_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "L4LIB_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void i4_to_l4_test ( ) /******************************************************************************/ /* Purpose: I4_TO_L4_TEST tests I4_TO_L4. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int i4; int l4; printf ( "\n" ); printf ( "I4_TO_L4_TEST\n" ); printf ( " I4_TO_L4 converts an I4 to an L4.\n" ); printf ( "\n" ); printf ( " I4 L4\n" ); printf ( "\n" ); for ( i4 = -5; i4 <= 5; i4++ ) { l4 = i4_to_l4 ( i4 ); printf ( " %2d %1d\n", i4, l4 ); } return; } /******************************************************************************/ void i4_to_l4vec_test ( ) /******************************************************************************/ /* Purpose: I4_TO_L4VEC_TEST tests I4_TO_L4VEC. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int i4; int j; int n = 8; int *l4vec; printf ( "\n" ); printf ( "I4_TO_L4VEC_TEST\n" ); printf ( " I4_TO_L4VEC converts an I4 to an L4VEC.\n" ); printf ( "\n" ); printf ( " I4 L4VEC\n" ); printf ( "\n" ); for ( i4 = 0; i4 <= 10; i4++ ) { l4vec = i4_to_l4vec ( i4, n ); printf ( " %2d", i4 ); for ( j = 0; j < n; j++ ) { printf ( " %1d", l4vec[j] ); } printf ( "\n" ); free ( l4vec ); } return; } /******************************************************************************/ void l4_to_i4_test ( ) /******************************************************************************/ /* Purpose: L4_TO_I4_TEST tests L4_TO_I4. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int i4; int l4; printf ( "\n" ); printf ( "L4_TO_I4_TEST\n" ); printf ( " L4_TO_I4 converts an L4 to an I4.\n" ); printf ( "\n" ); printf ( " L4 I4\n" ); printf ( "\n" ); l4 = 0; i4 = l4_to_i4 ( l4 ); printf ( " %d %d\n", l4, i4 ); l4 = 1; i4 = l4_to_i4 ( l4 ); printf ( " %d %d\n", l4, i4 ); return; } /******************************************************************************/ void l4_to_s_test ( ) /******************************************************************************/ /* Purpose: L4_TO_S_TEST tests L4_TO_S. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 August 2016 Author: John Burkardt */ { int l4; char *s; printf ( "\n" ); printf ( "L4_TO_S_TEST\n" ); printf ( " L4_TO_S converts an L4 to a string.\n" ); printf ( "\n" ); printf ( " L4 S\n" ); printf ( "\n" ); l4 = 1; s = l4_to_s ( l4 ); printf ( " %d %s\n", l4, s ); l4 = 0; s = l4_to_s ( l4 ); printf ( " %d %s\n", l4, s ); l4 = 1999; s = l4_to_s ( l4 ); printf ( " %d %s\n", l4, s ); l4 = false; s = l4_to_s ( l4 ); printf ( " %d %s\n", l4, s ); l4 = true; s = l4_to_s ( l4 ); printf ( " %d %s\n", l4, s ); return; } /******************************************************************************/ void l4_uniform_test ( ) /******************************************************************************/ /* Purpose: L4_UNIFORM_TEST tests L4_UNIFORM. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 December 2007 Author: John Burkardt */ { int i; int seed; seed = 123456789; printf ( "\n" ); printf ( "L4_UNIFORM_TEST\n" ); printf ( " L4_UNIFORM computes pseudorandom logical values.\n" ); printf ( "\n" ); printf ( " The initial seed is %d\n", seed ); printf ( "\n" ); for ( i = 1; i <= 10; i++ ) { printf ( " %8d %d\n", i, l4_uniform ( &seed ) ); } return; } /******************************************************************************/ void l4_xor_test ( ) /******************************************************************************/ /* Purpose: L4_XOR_TEST tests L4_XOR. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int i; int j; int l1; int l2; int l4; printf ( "\n" ); printf ( "L4_XOR_TEST\n" ); printf ( " L4_XOR computes the exclusive OR of two L4's\n" ); printf ( "\n" ); printf ( " L1 L2 L4_XOR(L1,L2)\n" ); printf ( "\n" ); for ( j = 0; j <= 1; j++ ) { l1 = ( j == 1 ); for ( i = 0; i <= 1; i++ ) { l2 = ( i == 1 ); l4 = l4_xor ( l1, l2 ); printf ( " %d %d %d\n", l1, l2, l4 ); } } return; } /******************************************************************************/ void l4mat_print_test ( ) /******************************************************************************/ /* Purpose: L4MAT_PRINT_TEST tests L4MAT_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 03 November 2011 Author: John Burkardt */ { int *a; int i; int j; int m = 20; int n = 50; a = ( int * ) malloc ( m * n * sizeof ( int ) ); printf ( "\n" ); printf ( "L4MAT_PRINT_TEST\n" ); printf ( " L4MAT_PRINT prints a logical matrix.\n" ); for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { a[i+j*m] = ( ( i + 1 ) % ( j + 1 ) == 0 ); } } l4mat_print ( m, n, a, " A(I,J) = I+1 is divisible by J+1" ); free ( a ); return; } /******************************************************************************/ void l4mat_print_some_test ( ) /******************************************************************************/ /* Purpose: L4MAT_PRINT_SOME_TEST tests L4MAT_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int *a; int i; int j; int m = 20; int n = 50; a = ( int * ) malloc ( m * n * sizeof ( int ) ); printf ( "\n" ); printf ( "L4MAT_PRINT_SOME_TEST\n" ); printf ( " L4MAT_PRINT_SOME prints some of a logical matrix.\n" ); printf ( "\n" ); printf ( " Here, our matrix is 20x50, but we print rows 4:14, columns 0:4\n" ); for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { a[i+j*m] = ( ( i + 1 ) % ( j + 1 ) == 0 ); } } l4mat_print_some ( m, n, a, 4, 0, 14, 4, " A(I,J) = I+1 is divisible by J+1" ); free ( a ); return; } /******************************************************************************/ void l4mat_transpose_print_test ( ) /******************************************************************************/ /* Purpose: L4MAT_TRANSPOSE_PRINT_TEST tests L4MAT_TRANSPOSE_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int *a; int i; int j; int m = 20; int n = 50; a = ( int * ) malloc ( m * n * sizeof ( int ) ); printf ( "\n" ); printf ( "L4MAT_TRANSPOSE_PRINT_TEST\n" ); printf ( " L4MAT_TRANSPOSE_PRINT prints a logical matrix, transposed.\n" ); for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { a[i+j*m] = ( ( i + 1 ) % ( j + 1 ) == 0 ); } } l4mat_transpose_print ( m, n, a, " A(I,J) = I+1 is divisible by J+1" ); free ( a ); return; } /******************************************************************************/ void l4mat_transpose_print_some_test ( ) /******************************************************************************/ /* Purpose: L4MAT_TRANSPOSE_PRINT_SOME_TEST tests L4MAT_TRANSPOSE_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int *a; int i; int j; int m = 20; int n = 50; a = ( int * ) malloc ( m * n * sizeof ( int ) ); printf ( "\n" ); printf ( "L4MAT_TRANSPOSE_PRINT_SOME_TEST\n" ); printf ( " L4MAT_TRANSPOSE_PRINT_SOME prints some of a logical matrix, transposed.\n" ); printf ( "\n" ); printf ( " Here, our matrix is 20x50, but we print rows 4:14, columns 0:4\n" ); for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { a[i+j*m] = ( ( i + 1 ) % ( j + 1 ) == 0 ); } } l4mat_transpose_print_some ( m, n, a, 4, 0, 14, 4, " A(I,J) = I+1 is divisible by J+1" ); free ( a ); return; } /******************************************************************************/ void l4mat_uniform_new_test ( ) /******************************************************************************/ /* Purpose: L4MAT_UNIFORM_NEW_TEST tests L4MAT_UNIFORM_NEW. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 December 2014 Author: John Burkardt */ { int *l; int m = 5; int n = 4; int seed; seed = 123456789; printf ( "\n" ); printf ( "L4MAT_UNIFORM_NEW_TEST\n" ); printf ( " L4MAT_UNIFORM_NEW computes a vector of\n" ); printf ( " pseudorandom logical values.\n" ); printf ( "\n" ); printf ( " The initial seed is %d\n", seed ); l = l4mat_uniform_new ( m, n, &seed ); l4mat_print ( m, n, l, " Uniform L4MAT:" ); free ( l ); return; } /******************************************************************************/ void l4vec_next_test ( ) /******************************************************************************/ /* Purpose: L4VEC_NEXT_TEST tests L4VEC_NEXT. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 November 2015 Author: John Burkardt */ { int done; int i; int l4vec[3]; int n = 3; printf ( "\n" ); printf ( "L4VEC_NEXT_TEST\n" ); printf ( " L4VEC_NEXT generates logical vectors in order.\n" ); printf ( "\n" ); for ( i = 0; i < n; i++ ) { l4vec[i] = 0; } done = 0; for ( ; ; ) { printf ( " " ); for ( i = 0; i < n; i++ ) { printf ( "%d", l4vec[i] ); } printf ( "\n" ); if ( done ) { break; } l4vec_next ( n, l4vec ); done = 1; for ( i = 0; i < n; i++ ) { if ( ! l4vec[i] ) { done = 0; } } } return; } /******************************************************************************/ void l4vec_print_test ( ) /******************************************************************************/ /* Purpose: L4VEC_PRINT_TEST tests L4VEC_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 23 November 2015 Author: John Burkardt */ { int i; int j; int n = 20; int lvec[21]; printf ( "\n" ); printf ( "L4VEC_PRINT_TEST\n" ); printf ( " L4VEC_PRINT prints an L4VEC.\n" ); lvec[0] = 0; lvec[1] = 0; for ( i = 2; i <= n; i++ ) { lvec[i] = 1; for ( j = 2; j < i; j++ ) { if ( ( i % j ) == 0 ) { lvec[i] = 0; break; } } } l4vec_print ( n, lvec, " Is I Prime?:" ); return; } /******************************************************************************/ void l4vec_uniform_new_test ( ) /******************************************************************************/ /* Purpose: L4VEC_UNIFORM_NEW_TEST tests L4VEC_UNIFORM_NEW. Licensing: This code is distributed under the GNU LGPL license. Modified: 20 December 2014 Author: John Burkardt */ { int *l; int n = 10; int seed; seed = 123456789; printf ( "\n" ); printf ( "L4VEC_UNIFORM_NEW_TEST\n" ); printf ( " L4VEC_UNIFORM_NEW computes a vector of\n" ); printf ( " pseudorandom logical values.\n" ); printf ( "\n" ); printf ( " The initial seed is %d\n", seed ); l = l4vec_uniform_new ( n, &seed ); l4vec_print ( n, l, " Uniform L4VEC:" ); free ( l ); return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }