00001
00002
00003
00004
00005
00006
00007
00008 #include "util.h"
00009 #include "array.h"
00010
00011
00012
00013
00014
00015
00016
00017 static int regArrayTest ();
00018 static int arrayTest ();
00019 static int arrayGrowing ();
00020
00021
00022
00023 static int N = 10000000;
00024
00025 int
00026 util_test ()
00027 {
00028 return 0;
00029
00030 int i;
00031 int M = 100;
00032 for (i = 0; i < M; i++)
00033 {
00034 regArrayTest ();
00035 arrayTest ();
00036 arrayGrowing ();
00037 }
00038
00039 exit (0);
00040 }
00041
00042 static int
00043 regArrayTest ()
00044 {
00045 int j;
00046 int *foo = (int *) malloc (sizeof (int) * N);
00047 printf ("Testing straight-up array\n");
00048 for (j = 0; j < N; j++)
00049 {
00050 foo[j] = j;
00051 }
00052 free (foo);
00053 printf ("Done testing straight-up array\n");
00054 return 0;
00055 }
00056
00057 static int
00058 arrayTest ()
00059 {
00060 int j;
00061 printf ("Testing array_t preallocated\n");
00062 array_t *bar = array_alloc (int, N);
00063 for (j = 0; j < N; j++)
00064 {
00065 array_insert (int, bar, j, j);
00066 }
00067 array_free (bar);
00068 printf ("Done testing arrayt preallocated\n");
00069 return 0;
00070 }
00071
00072 static int
00073 arrayGrowing ()
00074 {
00075 int j;
00076 printf ("Testing array_t nonpreallocated\n");
00077 array_t *widget = array_alloc (int, 0);
00078 for (j = 0; j < N; j++)
00079 {
00080 array_insert_last (int, widget, j);
00081 }
00082 array_free (widget);
00083 printf ("Done testing non-preallocated array\n");
00084 return 0;
00085 }