Ejemplo n.º 1
0
//! tests <code>ret= .func(arg,arg);</code> ...
int test1()
{
	Integer toto  ;
	toto.seeding((long unsigned int)0);
#ifdef GIVARO_DEBUG
	cout << "this is a random() number : " << toto.random() << endl;
#else
        toto.random();
#endif

	toto.seeding();
#ifdef GIVARO_DEBUG
	cout << "this is a random() number : " << toto.random() << endl;
#else
        toto.random();
#endif

    Integer::seeding();
#ifdef GIVARO_DEBUG
	cout << "this is a random() number : " << toto.random() << endl;
#else
        toto.random();
#endif

	Integer un(26);
	Integer autre(511);
	Integer large( Integer::one<<3000);
#ifdef GIVARO_DEBUG
	cout << "random...............OK" << endl;
#endif
	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_between(un,autre);
		//cout << tata << endl;
		if (tata < un || tata >= autre) {
			cout << "random_between  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "random_between.......OK" << endl;
#endif

	unsigned long trois = 3 ;
	unsigned long petits = 6 ;
	unsigned long grands = 300 ;
	//std::vector<int> T(1<<petits) ;

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_between(trois,petits);
		//cout << tata << endl;
		//T[tata] += 1 ;
		if (tata < (1<<trois) || tata >= (1<<petits) ) {
			cout << "random_between_exp  failed" << endl;
			return -1  ;
		}
	}
	//    for (size_t i = 0 ; i < 1<<petits ; ++i) cout << T[i] << " " ;
#ifdef GIVARO_DEBUG
	cout << "random_between_exp...OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_exact(petits);
		if ( tata.bitsize() != petits ) {
			//        cout << tata << endl;
			cout << "random_exact_exp  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "random_exact_exp.....OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_exact(autre);
		//        cout << tata << endl;
		if ( tata.bitsize() != autre.bitsize() ){
			cout << "random_exact  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "random_exact.........OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_lessthan_2exp(grands);
		if ( tata.bitsize() > grands ) {
			//        cout << tata << endl;
			cout << "random_lessthan_2exp  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "random_lessthan_2exp.....OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.random_lessthan(large);
		//        cout << tata << endl;
		if ( tata.bitsize() > large.bitsize() ){
			cout << "random_lessthan  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "random_lessthan.........OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.nonzerorandom(petits);
		if (tata == 0 || tata >= 1<<petits) {
			//        cout << tata << endl;
			cout << "nonzerorandom  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "nonzerorandom_exp....OK" << endl;
#endif

	for (size_t i = 0 ; i < 5000 ; ++i) {
		Integer tata = toto.nonzerorandom(autre);
		if (tata == 0 || tata >= autre) {
			       cout << tata << endl;
			cout << tata << "nonzerorandom  failed" << endl;
			return -1  ;
		}
	}
#ifdef GIVARO_DEBUG
	cout << "nonzerorandom........OK" << endl;
#endif

	return 0;

}