Пример #1
0
/*
 * Unit test for the vector_insert function. Runs some example
 * operations and checks that results are as expected, writing
 * messages to the terminal so that errors can be detected and
 * pinpointed.
 *
 * \return zero on success.
 */
int test_insert (void)
{
  static int const check[] = {
    102, 101, 209, 208, 207, 206, 205, 204, 203, 100, 99, 98, 97
  };
  static unsigned long const checklen = sizeof(check) / sizeof(*check);
  
  Vector vec;
  int ii;
  
  printf ("\nrunning test_insert...\n");
  
  vector_init (&vec);
  printf ("initialized: ");
  vector_dump (&vec);
  
  if (0 == vector_insert(&vec, 11, 42)) {
    printf ("test_insert ERROR: should not have been able to insert at invalid index\n");
    vector_destroy (&vec);
    return -1;
  }
  
  for (ii = -3; ii < 3; ++ii) {
    if (0 != vector_insert (&vec, 0, 100+ii)) {
      printf ("test_insert ERROR: could not insert %d at pos 0\n", 100+ii);
      vector_destroy (&vec);
      return -1;
    }
    printf ("inserted %3d at pos 0: ", 100+ii);
    vector_dump (&vec);
  }
  
  for (; ii < 10; ++ii) {
    if (0 != vector_insert (&vec, 2, 200+ii)) {
      printf ("test_insert ERROR: could not insert %d at pos 2\n", 200+ii);
      vector_destroy (&vec);
      return -1;
    }
    printf ("inserted %3d at pos 2: ", 200+ii);
    vector_dump (&vec);
  }
  
  if (checklen != vec.len) {
    printf ("test_insert ERROR: vector length should be %lu but is %lu\n", checklen, vec.len);
    vector_destroy (&vec);
    return -2;
  }
  
  for (ii = 0; ii < checklen; ++ii)
    if (vec.arr[ii] != check[ii]) {
      printf ("test_insert ERROR: arr[%d] should be %d but is %d\n", ii, check[ii], vec.arr[ii]);
      vector_destroy (&vec);
      return -1;
    }
  
  printf ("test_insert SUCCESS\n");
  
  vector_destroy (&vec);
  return 0;
}
Пример #2
0
/*
 * Unit test for the vector_prepend function. Runs some example
 * operations and checks that results are as expected, writing
 * messages to the terminal so that errors can be detected and
 * pinpointed.
 *
 * \return zero on success.
 */
int test_prepend (void)
{
  Vector vec;
  int ii;
  
  printf ("\nrunning test_prepend...\n");
  
  vector_init (&vec);
  printf ("initialized: ");
  vector_dump (&vec);
  
  for (ii = -3; ii < 10; ++ii) {
    if (0 != vector_prepend (&vec, ii)) {
      printf ("test_prepend ERROR: could not prepend %d\n", ii);
      vector_destroy (&vec);
      return -1;
    }
    printf ("prepended %2d: ", ii);
    vector_dump (&vec);
  }
  
  for (ii = 0; ii < 13; ++ii)
    if (vec.arr[ii] != 9-ii) {
      printf ("test_prepend ERROR: arr[%d] should be %d but is %d\n", ii, 9-ii, vec.arr[ii]);
      vector_destroy (&vec);
      return -1;
    }
  
  printf ("test_prepend SUCCESS\n");
  
  vector_destroy (&vec);
  return 0;
}
Пример #3
0
/* Data initialization */
void
init_data(char *conf_file, vector_t * (*init_keywords) (void))
{
	/* Init Keywords structure */
	keywords = vector_alloc();
	(*init_keywords) ();

#if 0
	/* Dump configuration */
	vector_dump(keywords);
	dump_keywords(keywords, 0);
#endif

	/* Stream handling */
	current_keywords = keywords;
	read_conf_file((conf_file) ? conf_file : CONF);
	free_keywords(keywords);
}
void options_dump(const options_t * options) {
    vector_dump(options->optspecs);
}
Пример #5
0
/*
 * Unit test for the vector_remove function. Runs some example
 * operations and checks that results are as expected, writing
 * messages to the terminal so that errors can be detected and
 * pinpointed.
 *
 * \return zero on success.
 */
int test_remove (void)
{
  static unsigned long const remlist[] = { 9, 0, 4, 4 };
  static unsigned long const remlistlen = sizeof(remlist) / sizeof(*remlist);
  
  static int const check[] = { 101, 102, 103, 104, 107, 108 };
  static unsigned long const checklen = sizeof(check) / sizeof(*check);
  
  Vector vec;
  int ii;
  
  printf ("\nrunning test_remove...\n");
  
  vector_init (&vec);
  printf ("initialized: ");
  vector_dump (&vec);
  
  if (0 == vector_remove(&vec, 11)) {
    printf ("test_remove ERROR: should not have been able to remove at invalid index\n");
    vector_destroy (&vec);
    return -1;
  }
  
  for (ii = 0; ii < 10; ++ii) {
    if (0 != vector_append (&vec, 100+ii)) {
      printf ("test_remove ERROR: could not append %d\n", 100+ii);
      vector_destroy (&vec);
      return -1;
    }
    printf ("appended %2d: ", 100+ii);
    vector_dump (&vec);
  }
  
  for (ii = 0; ii < remlistlen; ++ii) {
    if (0 != vector_remove (&vec, remlist[ii])) {
      printf ("test_remove ERROR: could not remove pos %lu\n", remlist[ii]);
      vector_destroy (&vec);
      return -1;
    }
    printf ("removed pos %lu: ", remlist[ii]);
    vector_dump (&vec);
  }
  
  if (0 == vector_remove(&vec, vec.len)) {
    printf ("test_remove ERROR: should not have been able to remove beyond end\n");
    vector_destroy (&vec);
    return -1;
  }
  
  if (checklen != vec.len) {
    printf ("test_remove ERROR: vector length should be %lu but is %lu\n", checklen, vec.len);
    vector_destroy (&vec);
    return -2;
  }
  
  for (ii = 0; ii < checklen; ++ii)
    if (vec.arr[ii] != check[ii]) {
      printf ("test_remove ERROR: arr[%d] should be %d but is %d\n", ii, check[ii], vec.arr[ii]);
      vector_destroy (&vec);
      return -1;
    }
  
  printf ("test_remove SUCCESS\n");
  
  vector_destroy (&vec);
  return 0;
}
Пример #6
0
 void print() const
 {
     vector_dump( m_array_to_copy_from , this->m_size );
 }
Пример #7
0
 void print() const
 {
     vector_dump( m_array , m_size );
 }