Beispiel #1
0
/* Prueba que la funcion comparar se ejecute correctamente. */
void prueba_comparar() {

	/* Declaro los vectores a utilizar. */
	int vacio[] = {};
	int unico[] = { 5 };
	int vec1[] = { 1, 2, 3, 4, 5 };
	int vec2[] = { 1, 2, 5 };
	int vec3[] = { 5, 8, 9 };
	/* Declaro los largos de los vectores */
	int nvacio = 0;
	int nunico = 1;
	int nvec1 = 5;
	int nvec2 = 3;
	int nvec3 = 3;

	print_test("Prueba comparar vacio, unico", 
		comparar(vacio, nvacio, unico, nunico) == -1);
	print_test("Prueba comparar unico, vec3", 
		comparar(unico, nunico, vec3, nvec3) == -1);
	print_test("Prueba comparar vec1, vec1", 
		comparar(vec1, nvec1, vec1, nvec1) == 0);
	print_test("Prueba comparar vec2, vec1", 
		comparar(vec2, nvec2, vec1, nvec1) == 1);
	print_test("Prueba comparar vec3, vec2", 
		comparar(vec3, nvec3, vec2, nvec2) == 1);

}
Beispiel #2
0
int
main (void) {
	TestStruct* data;

	/* save */
	printf("Saving...\n");
	data = (TestStruct*)malloc(sizeof(TestStruct));
	if (data == NULL) {
		fprintf(stderr, "malloc(): %s\n", strerror(errno));
		return 1;
	}
	data->id = 500;
	data->name = "Elanthis";
	data->hp = 70;
	data->hp_max = 75;
	print_test(data);
	save_test(data);
	free(data);

	/* load */
	printf("Loading...\n");
	data = load_test();
	if (data == NULL) {
		fprintf(stderr, "load_data(): %s\n", strerror(errno));
		return 1;
	}
	print_test(data);
	free(data);

	return 0;
}
Beispiel #3
0
void pruebas_heap_vacio(void){
    heap_t* heap=heap_crear(int_cmp);
    print_test("Heap vacío...",heap_cantidad(heap)==0);
    print_test("Ver max es NULL...",heap_ver_max(heap)==NULL);
    print_test("Desencolar es NULL...",heap_desencolar(heap)==NULL);
    heap_destruir(heap,NULL);
}
void pruebas_cola_de_pilas() {
	printf("\nINICIO DE PRUEBAS CON COLA DE PILAS\n");
	
	/* Declaro las variables a utilizar*/
	cola_t* cola = cola_crear();
	pila_t* pila = pila_crear();
	pila_t* pila2 = pila_crear();
	int a = 1, b = 2, c = 3, d = 4, e = 5;
	int* p_a = &a;
	int* p_b = &b;
	int* p_c = &c;
	int* p_d = &d;
	int* p_e = &e;
	
	/* Inicio de pruebas */
	// Apilo todos los elementos
	pila_apilar(pila, p_a);
	pila_apilar(pila, p_b);
	pila_apilar(pila, p_c);
	pila_apilar(pila2, p_d);
	pila_apilar(pila2, p_e);
	
	// Encolo las pilas
	print_test("Prueba encolar pila 1", cola_encolar(cola, pila));
	print_test("Prueba encolar pila 2", cola_encolar(cola, pila2));
	
	/* Destruyo la cola */
	cola_destruir(cola, pila_destruir_wrapper);
	print_test("La cola fue destruida", true);
}
Beispiel #5
0
void pruebas_cola_destruir(){
	//19
	punto* p = malloc(sizeof(punto));
	p->x = 1;
	p->y = 2;

	cola_t *cola =cola_crear();
	cola_encolar(cola, p);
	print_test("Ver primero igual a struct punto", cola_ver_primero(cola) == p);
	cola_desencolar(cola);
	//20
	print_test("Desencolar struct punto, cola vacia", cola_esta_vacia(cola));
	//21
	cola_encolar(cola, p);
	cola_destruir(cola, destruir_punto);
	print_test("Destruir cola con struct punto encolado", true);
	//22
	cola_t* cola_1 = cola_crear();
	for(int i = 0; i<500; i++){
		if (i%2==0)
			cola_encolar(cola_1, p);
		else
			cola_desencolar(cola_1);
	}
	print_test("Intercalar encolar y desencolar", cola_esta_vacia(cola_1));
	cola_destruir(cola_1, destruir_punto);
	destruir_punto(p);

}
Beispiel #6
0
void pruebas_volumen(){
  printf("***** Inicio de pruebas de volumen *****\n");
  
  bool ok = true;

  cola_t* cola = cola_crear();
  print_test("cola esta vacia", cola_esta_vacia(cola));
  int vec[TAM_PRUEBAS];
  for(int a =0; a < TAM_PRUEBAS; a++){
    vec[a] = a;
    ok = cola_encolar(cola, &vec[a]);
    if (!ok) break;    
  }
  
  print_test("Todos los elementos fueron encolados con exito", ok);

  for(int b = 0; b < TAM_PRUEBAS ; b++){
    ok = *(int*)cola_desencolar(cola) == vec[b] ? true : false ;
    if (!ok) break;
  }
  
  print_test("Todos los elementos fueron desencolados en orden", ok);
  
  cola_destruir(cola, NULL);
}
Beispiel #7
0
/* Prueba que la funcion swap se ejecute correctamente. */
void prueba_swap() {
	int a = 5, b = 6;
	swap(&a,&b);
	print_test("Prueba swap 1", (a==6 && b==5));

	a = 10, b = -10;
	swap(&a,&b);
	print_test("Prueba swap 2", (a==-10 && b==10));
}
Beispiel #8
0
void pruebas_cola_vacia(){
  printf("***** Inicio de pruebas cola vacia *****\n");
  cola_t* cola = cola_crear();
  print_test("cola creada con exito  ",cola!=NULL);
  print_test("cola esta vacia ",cola_esta_vacia(cola));
  print_test("cola ver primero devuelve NULL", !cola_ver_primero(cola));
  print_test("cola desencolar devuelve NULL", !cola_desencolar(cola));	
  cola_destruir(cola,NULL);
}
Beispiel #9
0
int test_list(void)
{
	int ret = 0;
	allocator_t *allocator;
	iterator_t it,next;
	container_t *ct;

	/*
	 *allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC);
	 */
	allocator = allocator_creator(ALLOCATOR_TYPE_CDS_MALLOC);
	allocator_cds_init(allocator, 0, 0, 1024);

	dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator);

	ct = container_creator(CONTAINER_TYPE_LIST,allocator);

	container_list_init(ct,sizeof(struct test));
	/*
	 *container_push_front(ct,&test);
	 *container_push_front(ct,&test2);
	 *container_push_front(ct,&test3);
	 */
	dbg_str(DBG_CONTAINER_DETAIL,"run at here");
	container_push_back(ct,&test);
	container_push_back(ct,&test2);
	container_push_back(ct,&test3);


	dbg_str(DBG_CONTAINER_DETAIL,"iter ordinal");
	for(	it = container_begin(ct); 
			!iterator_equal(it,container_end(ct));
			it = iterator_next(it))
	{
		print_test((struct test *)iterator_get_pointer(it));
	}

	dbg_str(DBG_CONTAINER_DETAIL,"iter insert test");
	int i = 0;
	for(	it = container_begin(ct); 
			!iterator_equal(it,container_end(ct));
			it = iterator_next(it),i++)
	{
		if(i == 1){
			break;
		}
	}
	dbg_str(DBG_CONTAINER_DETAIL,"it list_head:%p",it.pos.list_head_p);
	container_insert(ct,it,&test4);

	dbg_str(DBG_CONTAINER_DETAIL,"iter delte test");
	container_for_each_safe(it,next,ct){
		//container_delete(ct,it);
		print_test((struct test *)iterator_get_pointer(it));
	}
int main(int argc, char *argv[])
{
//    FILE *foo;
    int i=0;
    int j=0;
    float total_time;
    float total_rate;
    
    struct command_def bmcommand;
    struct result_def bmresult;
    
#if 1
        if(bmcommand_from_console(argc, argv, &bmcommand) == BMTRUE)
        {
            print_test(bmcommand);
            bmresult = benchmark(bmcommand);    
            print_result(bmcommand, bmresult);       
        }
//        printf("m: %d, p: %d, ip: %s, ds: %d, bs: %d\n",
//            bmcommand.mode,bmcommand.port_number,bmcommand.ip_address,bmcommand.total_data_size,bmcommand.buffer_size); 
        
#else
       for(i=256; i< 1459;i+=1202)
       {
       for(j=0;j<6;j++)
       {
       // fudging it for now...
        bmcommand.buffer_size = 2000;
        bmcommand.mode = RECEIVER;
        if(j>=3)
        {
            bmcommand.mode = SENDER;
            bmcommand.buffer_size = i;        
        }
        bmcommand.port_number = 50;
        bmcommand.protocol = TCP;
        // command.ip_address not needed for receiver  
        strcpy(bmcommand.ip_address,"192.168.0.50");
        // command.total_data_size not needed for receiver
        bmcommand.total_data_size = 100000000;

        print_test(bmcommand);
        bmresult = benchmark(bmcommand);
///        total_time = get_total_time(bmresult.start_time, bmresults.stop_time);
        print_result(bmcommand, bmresult);
        if(j<=3)
            sleep(1);
        else
            sleep(4);
        }   
       }
#endif
    return 0;
}
/* Pruebas para un vector de tamanio 0*/
void pruebas_vector_nulo()
{
	printf("INICIO DE PRUEBAS CON VECTOR DE TAMANIO 0\n");

	/* Declaro las variables a utilizar*/
	vector_t* vec = vector_crear(0);

	/* Inicio de pruebas */
	print_test("crear vector con tamanio 0", vec != NULL);
	print_test("obtener tamanio vector es 0", vector_obtener_tamanio(vec) == 0);

	/* Pruebo que guardar en un vector de tamanio 0 devuelve false siempre (no se puede guardar) */
	print_test("guardar en vec[0] es false", !vector_guardar(vec, 0, 5));
	print_test("guardar en vec[1] es false", !vector_guardar(vec, 1, 10));
	print_test("guardar en vec[15] es false", !vector_guardar(vec, 15, 0));

	/* Pruebo que obtener valores de un vector de tamaño 0 devuelve false */
	int valor;
	print_test("obtener vec[0] es false", !vector_obtener(vec, 0, &valor));
	print_test("obtener vec[1] es false", !vector_obtener(vec, 1, &valor));

	/* Destruyo el vector*/
	vector_destruir(vec);
	print_test("el vector fue destruido", true);
}
void BinaryTreeTest::test_tree_height() {
  test_header( "tree height" );

  Tree<int> tree;
  print_test( tree.height() == 0 );

  tree.insert( 10 );
  print_test( tree.height() == 1 );

  tree.insert( 15 );
  print_test( tree.height() == 2 );

  tree.insert( 5 );
  print_test( tree.height() == 2 );
}
Beispiel #13
0
void json_report(FILE *f, struct criterion_global_stats *stats) {
    fprintf(f, JSON_BASE_TEMPLATE_BEGIN,
            stats->tests_passed,
            stats->tests_failed,
            stats->tests_crashed,
            stats->tests_skipped
        );

    fprintf(f, JSON_TESTSUITE_LIST_TEMPLATE_BEGIN);
    for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) {

        fprintf(f, JSON_TESTSUITE_TEMPLATE_BEGIN,
                ss->suite->name,
                ss->tests_passed,
                ss->tests_failed,
                ss->tests_crashed,
                ss->tests_skipped
            );

        fprintf(f, JSON_TEST_LIST_TEMPLATE_BEGIN);
        for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) {
            print_test(f, ts, ss);
            fprintf(f, ts->next ? ",\n" : "\n");
        }
        fprintf(f, JSON_TEST_LIST_TEMPLATE_END);

        fprintf(f, JSON_TESTSUITE_TEMPLATE_END);
        fprintf(f, ss->next ? ",\n" : "\n");
    }
    fprintf(f, JSON_TESTSUITE_LIST_TEMPLATE_END);

    fprintf(f, JSON_BASE_TEMPLATE_END);
}
Beispiel #14
0
uint8_t do_prompt() {

	print(PSTR(">"));
	char group[10];
//	scanf("%4s",group);
	scan_key(group,10);

	if (strcmp(group,"rf")==0) {
		return rf_do_prompt();
	} else if (strcmp(group,"io")==0) {
		return io_do_prompt();
	} else if (strcmp(group,"test")==0) {
		print_test();
		scan_test();
	} else if (strcmp(group,"timer")==0) {
		return timer_do_prompt();
	} else if (strcmp(group,"server")==0) {
		return server_do_prompt();
	} else if (strcmp(group,"client")==0) {
		return client_do_prompt();
	} else if (strcmp(group,"set")==0) {
		return set_do_prompt();
    } else if (strcmp(group,"pad")==0) {
        return pad_do_prompt();
	} else if (strcmp(group,".")==0) {
		return 0;
	} 
	return 1;
}
Beispiel #15
0
void pruebas_cola_vacia() {
	printf("\nINICIO DE PRUEBAS CON COLA VACIA\n");
	
	/* Declaro las variables a utilizar*/
	cola_t* cola = cola_crear();
	
	/* Inicio de pruebas */
	print_test("Prueba crear cola", cola != NULL);
	print_test("Prueba cola esta vacia despues de crearla", cola_esta_vacia(cola));
	print_test("Prueba ver primero cola vacia", !cola_ver_primero(cola));
	print_test("Prueba desencolar cola vacia", !cola_desencolar(cola));
	
	/* Destruyo la cola */
	cola_destruir(cola, NULL);
	print_test("La cola fue destruida", true);
}
Beispiel #16
0
static int dump2_test(bytecode_input_t *d, int i, int version)
{
    test_t test;
    int len;

    /* there is no short circuiting involved here */
    i = bc_test_parse(d, i, version, &test);

    switch (test.type) {
    case BC_NOT:
        printf("NOT ");
        i = dump2_test(d, i, version);
        break;

    case BC_ANYOF:
    case BC_ALLOF:
        len = test.u.aa.ntests;

        printf("%s({%d}\n\t",
               (test.type == BC_ANYOF) ? "ANYOF" : "ALLOF", len);

        while (len--) {
            i = dump2_test(d, i, version);
            printf("\t");
        }
        printf(")\n");
        break;

    default:
        print_test(&test);
        break;
    }

    return i;
}
Beispiel #17
0
int main()
{
	int *x, y; // I fully realize how silly it is to make x into a pointer.

	/* Sets x */
	for( *x = 0; *x < 10; ++( *x ) );

	/* Sets y */
	while( y != 90 )
	{
		if( y < 80 )
		{
			y = y + 10;
		}
		else if( y >= 80 )
		{
			++y;
		}
	}

	/* Prints x + y */
	print_test( *x, y );

	return 0;
}
/* compress/decompress a file */
static void
handle_file(char *file, struct stat *sbp)
{
	off_t usize, gsize;
	char	outfile[PATH_MAX];

	infile = file;
	if (dflag) {
		usize = file_uncompress(file, outfile, sizeof(outfile));
#ifndef SMALL
		if (vflag && tflag)
			print_test(file, usize != -1);
#endif
		if (usize == -1)
			return;
		gsize = sbp->st_size;
	} else {
		gsize = file_compress(file, outfile, sizeof(outfile));
		if (gsize == -1)
			return;
		usize = sbp->st_size;
	}


#ifndef SMALL
	if (vflag && !tflag)
		print_verbage(file, (cflag) ? NULL : outfile, usize, gsize);
#endif
}
Beispiel #19
0
void xml_report(FILE *f, struct criterion_global_stats *stats) {
    fprintf(f, XML_BASE_TEMPLATE_BEGIN,
            stats->nb_tests,
            stats->tests_failed,
            stats->tests_crashed,
            stats->tests_skipped
        );

    for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) {

        fprintf(f, XML_TESTSUITE_TEMPLATE_BEGIN,
                ss->suite->name,
                ss->nb_tests,
                ss->tests_failed,
                ss->tests_crashed,
                ss->tests_skipped,
                ss->tests_skipped
            );

        for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) {
            print_test(f, ts, ss);
        }

        fprintf(f, XML_TESTSUITE_TEMPLATE_END);
    }

    fprintf(f, XML_BASE_TEMPLATE_END);
}
void BinaryTreeTest::test_node_children_are_null_by_default() {
  test_header( "node children are null by default" );

  Node<int> node;

  print_test( node.left == NULL && node.right == NULL );
}
Beispiel #21
0
int main(int argc, const char *argv[])
{
    V_NODE *head = NULL;
    int flag = 0;
    
    print_test();
    head = load_link();
    while(!flag)
    {
       
        print_list();
        switch(get_choice())
        {
            case 1:
                head = add_link(head);
                break;
            case 2:
                head = delete_link(head);
                break;
            case 3:
                print_link(head);
                break;
            case 4:
                flag = 1 ;
                save_link(head);
                break;
            default :
                break;
        }
    }
    return 0;
}
void OperatorOverloadingTest::check_map_item_set_type() {
  print_header( "map_item gets type correctly" );

  MapItem item( 'Z' );

  print_test( item.getType() == 'Z' );
}
void OperatorOverloadingTest::check_map_item_constructor() {
  print_header( "map_item constructor accepts char" );

  MapItem item( 'O' );

  print_test( item.getType() == 'O' );
}
void OperatorOverloadingTest::check_map_item_default_constructor() {
  print_header( "map_item default constructor initializes to E" );

  MapItem item;

  print_test( item.getType() == 'E' );
}
void BinaryTreeTest::test_node_creation_with_value() {
  test_header( "node creation with value" );

  int test_value = 42;
  Node<int> node( test_value );

  print_test( node.data == test_value );
}
void OperatorOverloadingTest::check_map_build() {
  print_header( "map builds correctly" );

  map->build( 0, 1, 'O' );
  codes[ 1 ] = 'O';

  print_test( map->getMapItem( 0, 1 ).getType() == 'O' );
}
void BinaryTreeTest::test_tree_is_full() {
  test_header( "tree is full" );

  Tree<int> tree;
  tree.insert( 50 );
  tree.insert( 100 );
  tree.insert( 25 );
  tree.insert( 12 );
  tree.insert( 35 );
  tree.insert( 30 );
  tree.insert( 40 );

  print_test( tree.isFull() );

  tree.insert( 5 );

  print_test( ! tree.isFull() );
}
  AdaptiveSizePolicyOutput(AdaptiveSizePolicy* size_policy, 
			   uint count) :
    _size_policy(size_policy) {
    if (UseAdaptiveSizePolicy && (AdaptiveSizePolicyOutputInterval > 0)) {
      _do_print = print_test(count);
    } else {
      _do_print = false;
    }
  } 
void BinaryTreeTest::test_tree_contains() {
  test_header( "tree insert and contains" );

  int something = 42;
  Tree<int> tree;
  tree.insert( something );

  print_test( tree.contains( something ) == true );
}
Beispiel #30
0
void QueueTest::clear_queue() {
  test_header( "clearing the queue (isEmpty and dequeue)" );

  while( ! queue->isEmpty() ) {
    queue->dequeue();
  }

  // Makes the assumption that program would fail if loop fails
  print_test( true );
}