Example #1
0
static void TestSortSearch(vector *alphabet)
{
  VectorSort(alphabet, CompareChar);	 // Sort into order again
  fprintf(stdout, "\nAfter sorting: ");
  VectorMap(alphabet, PrintChar, stdout);
  TestSearch(alphabet, 'J');	// Test searching capabilities
  TestSearch(alphabet, '$');
}
Example #2
0
int main()
{
	ModularHashingFunction hashingFunctionA(7);
	ModularHashingFunction hashingFunctionB(1597);

	NotReallyHash nrh;
	
	SeparateChainingHash schA(&hashingFunctionA, 7);
	SeparateChainingHash schB(&hashingFunctionB, 1597);

	LinearProbingHash lphA(&hashingFunctionA, ELEMENTS_IN_HASH);
	LinearProbingHash lphB(&hashingFunctionB, ELEMENTS_IN_HASH);

	// Fill the hashes with data

	std::cout << "Adding " << ELEMENTS_IN_HASH << " elements to the hashes\n";

	for(size_t i = 0; i < ELEMENTS_IN_HASH; i++)
	{
		nrh.Add(i);
		schA.Add(i);
		schB.Add(i);
		lphA.Add(i);
		lphB.Add(i);

		std::cout << "\r" << (((double)i * 100) / ELEMENTS_IN_HASH) << "%";
	}

	std::cout << std::endl << std::endl;

	nrh.PrintInfo();
	schA.PrintInfo();
	schB.PrintInfo();
	lphA.PrintInfo();
	lphB.PrintInfo();

	std::cout << std::endl;

	// Now test the hashes for performance
	TestSearch(&nrh, "Regular linked list");
	TestSearch(&schA, "SeparateChainingHash with 7 chains");
	TestSearch(&schB, "SeparateChainingHash with 1597 chains");
	TestSearch(&lphA, "LinearProbingHash with hashing function mod 7");
	TestSearch(&lphB, "LinearProbingHash with hashing function mod 1597");

	return 0;
}
Example #3
0
int
main(int argc, char* argv[])
{
    nsresult rv;
    nsIServiceManager* servMgr;

    rv = NS_InitXPCOM2(&servMgr, NULL, NULL);
    if (NS_FAILED(rv)) return rv;

    if (argc > 1 && nsCRT::strcmp(argv[1], "-trace") == 0)
        gTrace = PR_TRUE;

#ifdef DEBUG
    TestSegmentedBuffer();
#endif

#if 0   // obsolete old implementation
    rv = NS_NewPipe(&in, &out, 4096 * 4);
    if (NS_FAILED(rv)) {
        printf("NewPipe failed\n");
        return -1;
    }

    rv = TestPipe(in, out);
    NS_RELEASE(in);
    NS_RELEASE(out);
    if (NS_FAILED(rv)) {
        printf("TestPipe failed\n");
        return -1;
    }
#endif
#if 0
    TestSearch("foo", 8);
    TestSearch("bar", 6);
    TestSearch("baz", 2);
#endif

    rv = TestChainedPipes();
    NS_ASSERTION(NS_SUCCEEDED(rv), "TestChainedPipes failed");
    RunTests(16, 1);
    RunTests(4096, 16);
    NS_RELEASE(servMgr);
    rv = NS_ShutdownXPCOM( NULL );
    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
    return 0;
}
Example #4
0
int main( int argc, char *argv[] )
{
#ifdef __SW_BW
    FILE *my_stdout;
    my_stdout = freopen( "tmp.log", "a", stdout );
    if( my_stdout == NULL ) {
        fprintf( stderr, "Unable to redirect stdout\n" );
        exit( -1 );
    }
#endif
    /*** Initialize ***/
    strcpy( ProgramName, strlwr( argv[0] ) );   /* store filename */

    /*** Test various functions ***/
    TestCompare();                              /* compare stuff */
    TestMove();                                 /* moving data about */
    TestCase();                                 /* upper/lowercase stuff */
    TestSearch();                               /* searching stuff */
    TestSubstring();                            /* substring stuff */
    TestToken();                                /* tokenizing stuff */
    TestLocale();                               /* locale stuff */
    TestError();                                /* error string stuff */
    TestFormatted();                            /* formatted I/O stuff */
    TestBounded();                              /* bounded string stuff */
#ifdef __X86__
    TestCompareF();
    TestMoveF();
    TestCaseF();
    TestSearchF();
    TestSubstringF();
    TestTokenF();
#endif

    /*** Print a pass/fail message and quit ***/
    if( NumErrors != 0 ) {
        printf( "%s: FAILURE (%d errors).\n", ProgramName, NumErrors );
        return( EXIT_FAILURE );
    }
    printf( "Tests completed (%s).\n", strlwr( argv[0] ) );
#ifdef __SW_BW
    fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) );
    fclose( my_stdout );
    _dwShutDown();
#endif
    return( 0 );
}