示例#1
0
Move test_bestmove(Position& pos, int maxdepth) {
	Move bestmove = MOVE_NONE;
	

	
	
	
	MoveStack mlist[MAX_MOVES];
	StateInfo st;
	Move m;

	// Generate all legal moves
	MoveStack* last = generate<MV_LEGAL>(pos, mlist);
	
	
	for (int it_depth = 1; it_depth <= maxdepth; ++it_depth) {
	
		bool bSearchPv = true;
		int alpha = -100000;
		int beta  =  100000;
		int score = alpha;
		
		for (MoveStack* cur = mlist; cur != last; cur++) {
			m = cur->move;
			pos.do_move(m, st);
			if (bSearchPv) {
				score = -test_search(pos, -beta, -alpha, it_depth - 1);
			} else {
				score = -test_search(pos, -alpha-1, -alpha, it_depth - 1);
				if (score > alpha) // in fail-soft ... && score < beta ) is common
					score = -test_search(pos, -beta, -alpha, it_depth - 1); // re-search
			}
			pos.undo_move(m);
			
			if(score > alpha) {
				alpha = score; // alpha acts like max in MiniMax
				bestmove = m;
			}
			bSearchPv = false;
		}
		
		
		cout << it_depth << " " << move_to_uci(bestmove, 0) << " " << score << endl;
		
	}
	
	
	return bestmove;
}
示例#2
0
static void TestUTF(skiatest::Reporter* reporter) {
    static const struct {
        const char* fUtf8;
        SkUnichar   fUni;
    } gTest[] = {
        { "a",                  'a' },
        { "\x7f",               0x7f },
        { "\xC2\x80",           0x80 },
        { "\xC3\x83",           (3 << 6) | 3    },
        { "\xDF\xBF",           0x7ff },
        { "\xE0\xA0\x80",       0x800 },
        { "\xE0\xB0\xB8",       0xC38 },
        { "\xE3\x83\x83",       (3 << 12) | (3 << 6) | 3    },
        { "\xEF\xBF\xBF",       0xFFFF },
        { "\xF0\x90\x80\x80",   0x10000 },
        { "\xF3\x83\x83\x83",   (3 << 18) | (3 << 12) | (3 << 6) | 3    }
    };

    for (size_t i = 0; i < SK_ARRAY_COUNT(gTest); i++) {
        const char* p = gTest[i].fUtf8;
        int         n = SkUTF8_CountUnichars(p);
        SkUnichar   u0 = SkUTF8_ToUnichar(gTest[i].fUtf8);
        SkUnichar   u1 = SkUTF8_NextUnichar(&p);

        REPORTER_ASSERT(reporter, n == 1);
        REPORTER_ASSERT(reporter, u0 == u1);
        REPORTER_ASSERT(reporter, u0 == gTest[i].fUni);
        REPORTER_ASSERT(reporter,
                        p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8));
    }

    test_utf16(reporter);
    test_search(reporter);
    test_refptr(reporter);
}
示例#3
0
文件: bs.c 项目: h0nzZik/school
int main(void)
{
	const int sz = 100;
	int i;
	int arr[sz];
	int last = 0;

	srand(time(NULL));

	for (i=0; i<sz; i++) {
		arr[i] = last + rand()%10;
		last = arr[i];
	}

//	arr_print(arr, sz);
	/*
	i = my_bsearch_norecursive(arr, sz, rand() % (arr[sz - 1] + 1) );
	if (i < 0)
		printf("smula\n");
	else
		printf("found at %d\n", i);
	*/
	i = test_search(arr, sz, rand() % (arr[sz - 1] + 1));
	/* missmatch */
	if (i == 0) {
		arr_print(arr, sz);
		return 1;
	}

	return 0;
}
示例#4
0
/* the main program... */
int main(int argc,char *argv[])
{
  char *srcdir;
  char fname[100];
  struct sigaction act;
  /* build the name of the file */
  srcdir=getenv("srcdir");
  if (srcdir==NULL)
    srcdir=".";
  snprintf(fname,sizeof(fname),"%s/nslcd-test.conf",srcdir);
  fname[sizeof(fname)-1]='\0';
  /* initialize configuration */
  cfg_init(fname);
  /* partially initialize logging */
  log_setdefaultloglevel(LOG_DEBUG);
  /* ignore SIGPIPE */
  memset(&act,0,sizeof(struct sigaction));
  act.sa_handler=SIG_IGN;
  sigemptyset(&act.sa_mask);
  act.sa_flags=SA_RESTART|SA_NOCLDSTOP;
  assert(sigaction(SIGPIPE,&act,NULL)==0);
  /* do tests */
  test_search();
  test_get();
  test_get_values();
  test_get_rdnvalues();
  test_two_searches();
  test_threads();
  test_connections();
  test_escape();
  return 0;
}
示例#5
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make map");
    mu_assert(make_random(map), "Didn't make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map),
            "Failed to properly sort the RadixMap");

    mu_assert(test_search(map), "Failed the search test");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map,
                map->contents[map->end/2].data.key);
        mu_assert(el != NULL, "Should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete");

        // test that the end is now the old value
        // but uint32 max so it trails off
        mu_assert(check_order(map),
                "RadixMap didn't stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
示例#6
0
文件: libtest.c 项目: posei/SmallerC
void test_mem(void) {
	test_memfn();
	test_chrfn();
	test_dmem();
	test_sort();
	test_search();
}
示例#7
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    mu_assert(make_random(map), "Didn't make a random fake radix map.");
    //In Zed's code was:
    //RadixMap_sort(map, 0);
    //I think we should sort it again because we do it every time we add a new value
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed to search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    while(map->end > 0) {

        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        //test taht the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
示例#8
0
// test for large number of elements
static char *test_operations() {
    size_t N = 200;
    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "failed to make the map");
    mu_assert(make_random(map), "did not make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map), "failed to properly sort the RadixMap");
    mu_assert(test_search(map), "failed the search test");
    mu_assert(check_order(map), "RadixMap not sorted after seach");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "did not delete element");
        mu_assert(old_end - 1 == map->end, "wrong size after delete");
        mu_assert(check_order(map), "did not stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
示例#9
0
int test_search(Position &pos, int alpha, int beta, int depth) {
	
	if(depth == 0) return test_eval(pos);
	bool bSearchPv = true;
	int score;
	
	MoveStack mlist[MAX_MOVES];
	StateInfo st;
	Move m;

	// Generate all legal moves
	MoveStack* last = generate<MV_LEGAL>(pos, mlist);
	
	if (mlist == last) {
		return -100000;
	}
	
	for (MoveStack* cur = mlist; cur != last; cur++) {
		m = cur->move;
		pos.do_move(m, st);
		if (bSearchPv) {
			score = -test_search(pos, -beta, -alpha, depth - 1);
		} else {
			score = -test_search(pos, -alpha-1, -alpha, depth - 1);
			if (score > alpha) // in fail-soft ... && score < beta ) is common
				score = -test_search(pos, -beta, -alpha, depth - 1); // re-search
		}
		pos.undo_move(m);
		if(score >= beta)
			return beta;   // fail-hard beta-cutoff
		if(score > alpha) {
			alpha = score; // alpha acts like max in MiniMax
		}
		bSearchPv = false;
	}
	
	
	
	return alpha; // fail-hard
}
示例#10
0
int
main (void) {

	test_new ();
	test_import ();
	test_split ();
	test_replace ();
	test_copy ();
	test_cut ();
	test_search ();
	test_tail_head ();
	return 0;
}
示例#11
0
文件: test.cpp 项目: semenovf/pfs
int main ()
{
    BEGIN_TESTS(0);

    test_constructors();
    test_assignments();
    test_access();
    test_iterators();
    test_capacity();
    test_operations();
    test_search();

    return END_TESTS;
}
示例#12
0
int
main (int argc, char **argv)
{
  g_type_init ();
  source = ol_lyric_source_new ();
  test_list_sources ();
  test_search ();
  test_search_default ();
  test_search_cancel ();
  test_empty_source ();
  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);
  g_object_unref (source);
  return 0;
}
示例#13
0
main()
{
	char *repo_name = "pds_demo.dat";
	char *ndx_name = "pds_demo.ndx";
	int status;

	status = pds_open( repo_name, ndx_name );
	if( status != PDS_SUCCESS ){
		fprintf(stderr, "pds_open failed: %d\n", status);
		exit(1);
	}
	test_store();
	test_search();

	// Close and reopen to check if the index got saved properly
	pds_close();
	status = pds_open( repo_name, ndx_name );
	if( status != PDS_SUCCESS ){
		fprintf(stderr, "pds_open failed: %d\n", status);
		exit(1);
	}
	test_search();
	test_delete();
	pds_close();

	status = pds_open( repo_name, ndx_name );
	if( status != PDS_SUCCESS ){
		fprintf(stderr, "pds_open failed: %d\n", status);
		exit(1);
	}
	test_search();

	pds_close();

	printf("Program terminated successfully\n");
}
示例#14
0
int main(int argc, char** argv)
{
	printf("OPERATION    TESTS\n");
	printf("==================\n\n");

	init (argc, argv);

	test_search();
	test_cmpOrder();
	test_format();

	printf("\ntest_operation RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);

	return nbError;
}
示例#15
0
// test for big number of elements
static char *test_RadixMap_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");
    mu_assert(make_random(map), "Didn't make a random fake radix map.");

    RadixMap_sort(map);
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed the search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    RadixMap_destroy(map);

    map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    debug("PUSHING VALUES");
    mu_assert(push_random_values(map), "Didn't push random values.");
    debug("VALUES PUSHED!");

    mu_assert(check_order(map), "Map wasn't sorted after pushes.");

    debug("DOING DELETES");
    while(map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        // test that the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
示例#16
0
int main() 
{
  // Allocate memory for a new list
  llist *list = (llist *)malloc(sizeof(llist));
  if (list == NULL) {
    printf("Unable to allocate memory\n");
    exit(1);
  }
  init_list(list);

  int option = 0;
  bool quit = false;

  // Display menu and prompt user for action
  while (!quit) {
    option = prompt_user();
    switch (option) {
      case 1:
	printf("\n\tNumber of elements in list: %d\n", list->length);
	print(list);
	break;
      case 2: test_insert(list);
	break;
      case 3: test_delete(list);
	break;
      case 4: test_search(list);
	break;
      case 5: print_backwards(list);
	break;
      case 6: printf("Bye.\n");
	quit = true;
	break;
    }
  }
  // call function to free memory for entire list
  delete_list(list);

  return 0;
}
示例#17
0
void test_procedure()
{
    if (!uci.engine_initialized)
        init_engine(position);

    assert(test_bitscan());
	assert(test_bittwiddles());
    assert(test_fen());
    assert(test_genmove());
    assert(test_make_unmake());
    assert(test_hash());
    assert(test_eval());
    assert(test_capture_gen());
    assert(test_check_gen());
    assert(test_alt_move_gen());
    assert(test_see());
    assert(test_position());
	assert(test_hash_table());
	assert(test_ep_capture());
	assert(test_book());
    test_search();
}
示例#18
0
void test_basic(dict *dct, const struct key_info *keys, const unsigned nkeys,
		const struct closest_lookup_info *cl_infos,
		unsigned n_cl_infos) {
    dict_itor *itor = dict_itor_new(dct);

    CU_ASSERT_TRUE(dict_verify(dct));

    for (unsigned i = 0; i < nkeys; ++i) {
	bool inserted = false;
	void **datum_location = dict_insert(dct, keys[i].key, &inserted);
	CU_ASSERT_TRUE(inserted);
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_PTR_NULL(*datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));

	for (unsigned j = 0; j <= i; ++j)
	    test_search(dct, itor, keys[j].key, keys[j].value);
	for (unsigned j = i + 1; j < nkeys; ++j)
	    test_search(dct, itor, keys[j].key, NULL);
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    if (dct->_vtable->insert == (dict_insert_func)hashtable_insert ||
	dct->_vtable->insert == (dict_insert_func)hashtable2_insert) {
	/* Verify that hashtable_resize works as expected. */
	dict *clone = dict_clone(dct, NULL);
	CU_ASSERT_TRUE(dict_verify(dct));
	if (dct->_vtable->insert == (dict_insert_func)hashtable_insert) {
	    CU_ASSERT_TRUE(hashtable_resize(dict_private(clone), 3));
	} else {
	    CU_ASSERT_TRUE(hashtable2_resize(dict_private(clone), 3));
	}
	CU_ASSERT_TRUE(dict_verify(dct));
	for (unsigned j = 0; j < nkeys; ++j)
	    test_search(clone, NULL, keys[j].key, keys[j].value);
	dict_free(clone);
    }

    if (dct->_vtable->clone) {
	dict *clone = dict_clone(dct, NULL);
	CU_ASSERT_PTR_NOT_NULL(clone);
	CU_ASSERT_TRUE(dict_verify(clone));
	CU_ASSERT_EQUAL(dict_count(clone), nkeys);
	for (unsigned i = 0; i < nkeys; ++i) {
	    test_search(clone, itor, keys[i].key, keys[i].value);
	}
	for (unsigned i = 0; i < nkeys; ++i) {
	    CU_ASSERT_TRUE(dict_remove(clone, keys[i].key));
	}
	dict_free(clone);
    }

    for (unsigned i = 0; i < nkeys; ++i)
	test_search(dct, itor, keys[i].key, keys[i].value);

    for (unsigned i = 0; i < nkeys; ++i) {
	bool inserted = false;
	void **datum_location = dict_insert(dct, keys[i].key, &inserted);
	CU_ASSERT_FALSE(inserted);
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_EQUAL(*datum_location, keys[i].value);

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    CU_ASSERT_PTR_NOT_NULL(itor);
    char *last_key = NULL;
    unsigned n = 0;
    for (dict_itor_first(itor); dict_itor_valid(itor); dict_itor_next(itor)) {
	CU_ASSERT_PTR_NOT_NULL(dict_itor_key(itor));
	CU_ASSERT_PTR_NOT_NULL(dict_itor_data(itor));
	CU_ASSERT_PTR_NOT_NULL(*dict_itor_data(itor));

	char *key = dict_itor_key(itor);
	bool key_matched = false;
	for (unsigned i = 0; i < nkeys; ++i) {
	    if (keys[i].key == key) {
		CU_ASSERT_EQUAL(*dict_itor_data(itor), keys[i].value);
		key_matched = true;
		break;
	    }
	}
	CU_ASSERT_TRUE(key_matched);

	if (dct->_vtable->insert != (dict_insert_func)hashtable_insert &&
	    dct->_vtable->insert != (dict_insert_func)hashtable2_insert) {
	    if (last_key) {
		CU_ASSERT_TRUE(strcmp(last_key, dict_itor_key(itor)) < 0);
	    }
	    last_key = dict_itor_key(itor);
	}

	++n;
    }
    CU_ASSERT_EQUAL(n, nkeys);
    last_key = NULL;
    n = 0;
    for (dict_itor_last(itor); dict_itor_valid(itor); dict_itor_prev(itor)) {
	CU_ASSERT_PTR_NOT_NULL(dict_itor_key(itor));
	CU_ASSERT_PTR_NOT_NULL(dict_itor_data(itor));
	CU_ASSERT_PTR_NOT_NULL(*dict_itor_data(itor));

	char *key = dict_itor_key(itor);
	bool key_matched = false;
	for (unsigned i = 0; i < nkeys; ++i) {
	    if (keys[i].key == key) {
		CU_ASSERT_EQUAL(*dict_itor_data(itor), keys[i].value);
		key_matched = true;
		break;
	    }
	}
	CU_ASSERT_TRUE(key_matched);

	if (dct->_vtable->insert != (dict_insert_func)hashtable_insert &&
	    dct->_vtable->insert != (dict_insert_func)hashtable2_insert) {
	    if (last_key) {
		CU_ASSERT_TRUE(strcmp(last_key, dict_itor_key(itor)) > 0);
	    }
	    last_key = dict_itor_key(itor);
	}

	++n;
    }
    CU_ASSERT_EQUAL(n, nkeys);

    for (unsigned i = 0; i < nkeys; ++i) {
	bool inserted = false;
	void **datum_location = dict_insert(dct, keys[i].key, &inserted);
	CU_ASSERT_FALSE(inserted);
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_PTR_NOT_NULL(*datum_location);
	*datum_location = keys[i].alt;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);

    for (unsigned i = 0; i < nkeys; ++i)
	test_search(dct, itor, keys[i].key, keys[i].alt);

    for (unsigned i = 0; i < nkeys; ++i) {
	test_search(dct, itor, keys[i].key, keys[i].alt);
	CU_ASSERT_TRUE(dict_remove(dct, keys[i].key));
	CU_ASSERT_TRUE(dict_verify(dct));

	CU_ASSERT_EQUAL(dict_remove(dct, keys[i].key), false);
	for (unsigned j = 0; j <= i; ++j) {
	    test_search(dct, itor, keys[j].key, NULL);
	}
	for (unsigned j = i + 1; j < nkeys; ++j) {
	    test_search(dct, itor, keys[j].key, keys[j].alt);
	}
    }

    for (unsigned i = 0; i < nkeys; ++i) {
	bool inserted = false;
	void **datum_location = dict_insert(dct, keys[i].key, &inserted);
	CU_ASSERT_TRUE(inserted);
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_PTR_NULL(*datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);
    CU_ASSERT_EQUAL(dict_clear(dct), nkeys);

    for (unsigned i = 0; i < nkeys; ++i) {
	bool inserted = false;
	void **datum_location = dict_insert(dct, keys[i].key, &inserted);
	CU_ASSERT_TRUE(inserted);
	CU_ASSERT_PTR_NOT_NULL(datum_location);
	CU_ASSERT_PTR_NULL(*datum_location);
	*datum_location = keys[i].value;

	CU_ASSERT_TRUE(dict_verify(dct));
    }
    test_closest_lookup(dct, cl_infos, n_cl_infos);
    dict_itor_free(itor);
    CU_ASSERT_EQUAL(dict_count(dct), nkeys);
    CU_ASSERT_EQUAL(dict_free(dct), nkeys);
}
示例#19
0
void test_search_moves()
{

    test_search("white en passant","8/1ppppppp/8/pP6/8/8/8/8","a6","-",2,"w","bxa6e.p.,b6");
    test_search("en pass set, but not available","8/8/8/3p4/P7/8/8/8/","d6","-",1,"w","a5");

    // pawn moves
    test_search("Should find 8 pawn moves","8/8/8/8/8/PPPPPPPP/8/8","-","-",8,"w","");
    test_search("Should find 8 pawn moves","8/8/pppppppp/8/8/8/8/8","-","-",8,"b","");
    test_search("Pawn blocked","8/8/p6p/P6P/8/8/8/8","-","-",0,"b","");

    // pawn capture moves
    test_search("Pawn capture (b)","8/8/p7/1P5P/8/8/8/8","-","-",2,"b","a5,xb5");
    test_search("Pawn capture (w)","8/8/1p5p/P7/8/8/8/8","-","-",2,"w","a6,xb6");

    //  pawn double moves
    test_search("Pawn Double","8/8/8/8/8/8/PPPPPPPP/8","-","-",16,"w","");
    test_search("Pawn Double #2","8/8/8/8/p7/8/PPPPPPPP/8","-","-",15,"w","");
    test_search("Pawn Double #3","8/pppppppp/8/8/8/8/8/8","-","-",16,"b","");
    test_search("Pawn Double #4","8/pppppppp/8/P7/8/8/8/8","-","-",15,"b","");

    // king moves
    test_search("King","8/8/8/8/8/8/3K4/8","-","-",8,"w","Kc1,Kd1,Ke1,Kc2,Ke2,Kc3,Kd3,Ke3");
    test_search("King","4k3/8/8/8/8/8/8/8","-","-",5,"b","kd8,kf8,kd7,ke7,kf7");

    // note one below has only 6 moves - 2 leave king exposed to check.
    // note for this to work, black must have 1 other piece still on board
    // or the alpha-beta search cuts off and stops the flg_is_illegal being set
    // correctly.
    test_search("King + capture","p7/8/8/8/8/3p4/3K4/8","-","-",6,"w","Kc1,Kd1,Ke1,Kc3,Kxd3,Ke3");

    // knight moves
    test_search("Knight","8/8/8/8/8/8/3N4/8","-","-",6,"w","Nb1,Nb3,Nc4,Ne4,Nf3,Nf1");
    test_search("Knight + capture","3k4/8/8/8/8/8/3N4/5p2","-","-",6,"w","Nb1,Nb3,Nc4,Ne4,Nf3,Nxf1");

    // rook moves
    test_search("Rook","4k3/8/8/8/8/8/R7/8","-","-",14,"w","Rb2,Rc2,Rd2,Re2,Rf2,Rg2,Rh2,Ra1,Ra3,Ra4,Ra5,Ra6,Ra7,Ra8");
    test_search("Black rook 1","7r/8/7B/8/8/8/PPPPPPPP/RNBQKBNR","-","-",9,"b","ra8,rb8,rc8,rd8,re8,rf8,rg8,rh7,rxh6");
    test_search("black rook with capture","8/8/8/8/2p5/1prp4/1P1P4/2R3K1","-","-",2,"b","rc2,rxc1");

    // bishop moves
    test_search("Bishop","8/8/3b4/8/8/8/8/4K3","-","-",11,"b","be7,bf8,bc5,bb4,ba3,be5,bf4,bg3,bh2,bc7,bb8");

    // test check_validation
    test_search("Check validation","8/8/8/8/8/1q6/1B6/1K6","-","-",2,"w","Ka1,Kc1");

    // pawn promotion
    test_search("pawn promotion","8/P7/8/8/3k4/8/8/8","-","-",1,"w","a8Q");
    test_search("pawn promotion with capture","1b6/P7/8/8/8/4k3/8/8","-","-",2,"w","a8Q,xb8Q");

    // disallow moves ending in check
    test_search("test in check","p7/8/8/8/8/4q3/4K3/8","-","-",3,"w","Kd1,Kf1,Kxe3");
}
示例#20
0
int main (int argc, char **argv) 
{
	CK_RV rv = CKR_OK;
	CK_FUNCTION_LIST_PTR pkcs11;
	CK_RV (*C_GetFunctionList) (CK_FUNCTION_LIST_PTR_PTR) = 0;
	char *lib_path, *string_to_search;
	unsigned int string_to_search_len;

	CK_INFO info;
	CK_SLOT_INFO slot_info;
	CK_ULONG slot_list_size = 8;
	CK_SLOT_ID slot_list[slot_list_size];

	CK_TOKEN_INFO token_info;

	CK_ULONG i;
	CK_SESSION_HANDLE session_handle;
	CK_OBJECT_HANDLE object_list[16];
	CK_ULONG object_list_size = 16, objects_found;
	
	if (argc >= 2) 
		lib_path = argv[1];

	if (argc >= 3)
		string_to_search = argv[2];

	string_to_search_len = strlen(string_to_search);

	void *pkcs11_so;
	pkcs11_so = dlopen (lib_path, RTLD_NOW);
	if (pkcs11_so == NULL) {
		fprintf (stderr, "Could not load library: %s\n", dlerror());
		return CKR_GENERAL_ERROR;
	}

	C_GetFunctionList = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR)) dlsym(pkcs11_so, "C_GetFunctionList");

	rv = C_GetFunctionList (&pkcs11);
	g_assert (rv == CKR_OK);

	/**/
	rv = pkcs11->C_Initialize (NULL);
	g_assert (rv == CKR_OK);
	
	rv = pkcs11->C_GetInfo (&info);
	g_assert (rv == CKR_OK);

	printf ("CK_INFO\n");
	printf ("PKCS#11 version: %u.%u\n", 
			info.cryptokiVersion.major,
			info.cryptokiVersion.minor);
	printf ("Manufacturer ID: %s\n", info.manufacturerID);
	printf ("Flags: %lx\n", (CK_ULONG) info.flags);
	printf ("Library Description: ");
	print_info (info.libraryDescription, 32);
	printf ("library version: %u.%u\n",
			info.libraryVersion.major,
			info.libraryVersion.minor);

	rv = pkcs11->C_GetSlotList (CK_TRUE, slot_list, &slot_list_size);
	g_assert (rv == CKR_OK);

	printf ("Number of slots: %lu\n", slot_list_size);
	printf ("Slot number: ");
	for (i = 0; i < slot_list_size; i++) {
		printf ("%lu ", (CK_ULONG) slot_list[i]);
	}
	printf ("\n");

	/**/
	rv = pkcs11->C_GetSlotInfo (slot_list[0], &slot_info);
	g_assert (rv == CKR_OK);

	printf ("CK_SLOT_INFO\n");
	printf ("Slot description: ");
	print_info (slot_info.slotDescription, 64);
	printf ("Manufacturer ID: ");
	print_info (slot_info.manufacturerID, 32);
	printf ("Flags: %lx\n", slot_info.flags);
	printf ("Hardware version: %u.%u\n",
			slot_info.hardwareVersion.major,
			slot_info.hardwareVersion.minor);
	printf ("Firmware version: %u.%u\n",
			slot_info.firmwareVersion.major,
			slot_info.firmwareVersion.minor);

	rv = pkcs11->C_GetTokenInfo (slot_list[0], &token_info);
	g_assert (rv == CKR_OK);

	test_session (pkcs11, slot_list[0]);

	rv = pkcs11->C_OpenSession (slot_list[0], CKF_SERIAL_SESSION, NULL, NULL, &session_handle);
	g_assert (rv == CKR_OK);

	test_search (pkcs11,
			slot_list[0],
			session_handle,
			string_to_search,
			string_to_search_len,
			object_list,
			object_list_size,
			&objects_found);

	test_attribute_value (pkcs11,
			slot_list[0],
			session_handle,
			object_list[0]);

	rv = pkcs11->C_CloseSession(session_handle);
	g_assert (rv == CKR_OK);

	rv = pkcs11->C_Finalize (NULL);
	g_assert (rv == CKR_OK);

	rv = dlclose(pkcs11_so);
	if (rv != 0) {
		fprintf (stderr, "Could not dlclose\n");
	}

	return 0;
}
示例#21
0
文件: tests.c 项目: twolfe18/Chess
int main(int argc, const char * argv[]) {
	
	get_ready();
	/*
	stupid_tests();
	printf("[tests.main]\tsanity check: sizeof(unsigned long) = %d\n",
					(int) sizeof(unsigned long));
	
	printf("[tests.main]\trunning tests....\n");
	
	Board board;
	setup(&board);
	printf("\n");
	printb(&board);
	printf("\n");
	
	test_to_play(&board);
	test_ply(&board);
	
	if(WIN == test_file_attacks())
		printf("[tests.file_attacks]\tpassed\n");
	else printf("[tests.file_attacks]\tFAILED!\n");
		
	if(WIN == test_rank_attacks())
		printf("[tests.rank_attacks]\tpassed\n");
	else printf("[tests.rank_attacks]\tFAILED!\n");
	
	if(WIN == test_initf())
		printf("[tests.initf]\t\tpassed\n");
	else printf("[tests.initf]\t\tFAILED!\n");
	
	if(WIN == test_tl_br_attacks())
		printf("[tests.tl_br_attacks]\tpassed\n");
	else printf("[tests.tl_br_attacks]\tFAILED!\n");
	
	if(WIN == test_knight_attacks())
		printf("[tests.knight_attacks]\tpassed\n");
	else printf("[tests.knight_attacks]\tFAILED!\n");
	
	if(WIN == test_king_attacks())
		printf("[tests.king_attacks]\tpassed\n");
	else printf("[tests.king_attacks]\tFAILED!\n");
	
	if(WIN == test_moves())
		printf("[tests.moves]\t\tpassed\n");
	else printf("[tests.moves]\t\tFAILED!\n");
	
	if(WIN == test_conversions())
		printf("[tests.conversions]\tpassed\n");
	else printf("[tests.conversions]\tFAILED!\n");
	
	if(WIN == test_apply_move())
		printf("[tests.apply_move]\tpassed\n");
	else printf("[tests.apply_move]\tFAILED!\n");
	*/
	
	if(WIN == test_search())
		printf("[tests.search]\t\tpassed\n");
	else printf("[tests.search]\t\tFAILED!\n");
	
	/* test_scout(); */
	
	clean_up();
	
	printf("\n[tests.main]\t\ttests complete\n");
	return EXIT_SUCCESS;
}
int main()
{
	struct trie *root = getNode();
	test_insert(&root);
	test_search(&root);
}