/**
 * Unlink a file and be sure it isn't there.
 **/
void unlink_file(){
	const char* testName = "unlink_file";
	int theFile = -1;
	int ret = 0;
	struct stat statbuf;
	
	theFile = open( testName, O_RDWR | O_CREAT, S_IRWXU );
	write( theFile, gData1, strlen( gData1 ) );
	close( theFile );
	
	errno = 0;
	ret = stat( testName, &statbuf );
	
	if( (ret == 0) && (errno == 0) ){ 
		ret = unlink( testName );

		if( (ret == 0) && (errno == 0) ){
			ret = stat( testName, &statbuf );
			if( (ret == -1) && (errno == ENOENT) ){
				printPass( testName );
			}else{
				printFail( testName, "Expected ret = -1 and errno = ENOENT" );
			}
		}else{
			printFail( testName, "Unlink() failed." );
		}
	}else{
		printFail( testName, "Failed to create the test file" );
	}
}
/**
 * Try to call unlink on the read only file system.
 **/
void unlink_rdonlyfs(){
	const char* testName = "unlink_rdonlyfs";
	const char* expectedError = "Read-only file system";	
	char* error = 0;	
	struct stat statbuf;
	
	errno = 0;
	int ret = unlink( "compressed_readonly/basic");
	int savedErrno = errno;
	
	if( ret != -1 ){
		printFail( testName, "Should not have been able to call unlink on the read only file system." );
		return;
	}
	
	if( savedErrno != 30 || strcmp( error = strerror( savedErrno ), expectedError ) != 0 ){
		printFail( testName, "The error was not correct." );
		return;
	}
	
	// Be sure the file is still there.
	if( stat( "compressed_readonly/basic", &statbuf ) != 0 ){
		printFail( testName, "The file is gone." );
		return;
	}
	
	printPass( testName );
	return;
}
/**
 * Unlink a file and create a new one with the same name (typical use case).
 **/
void unlink_recreate(){
	const char* testName = "unlink_recreate";
	int theFile = -1;
	int ret = 0;
	struct stat statbuf;
	
	theFile = open( testName, O_RDWR | O_CREAT, S_IRWXU );
	write( theFile, gData1, strlen( gData1 ) );
	close( theFile );
	
	unlink( testName );
	
	if( stat( testName, &statbuf ) == -1 ){
		theFile = open( testName, O_RDWR | O_CREAT, S_IRWXU );
		write( theFile, gData1, strlen( gData1 ) );
		close( theFile );
		
		if( stat( testName, &statbuf ) == 0 ){
			printPass( testName );
		}else{
			printFail( testName, "File was not recreated" );
		}
	}else{
		printFail( testName, "File was not removed" );
	}
}
/**
 * This is a lot like getdirentries().
 **/
void readdir_oneFile(){
	const char* testName = "readdir_oneFile";
	const char* dirName = "/readdir_oneFile";
	const char* fileName = "/readdir_oneFile/foo.txt";
	DIR* dirPtr = 0;
	const char* expectedResult = "foo.txt";
	struct dirent* dirEntry = 0;
	
	// Make a directory with a file.
	mkdir( dirName, 0777 );
	int theFile = open( fileName, O_CREAT | O_RDWR );
	write( theFile, gData1, 5 );
	close( theFile );

	errno = 0;
	dirPtr = opendir( dirName );
	
	if( (errno == 0) && (dirPtr > 0) ){
		dirEntry = readdir( dirPtr );
		
		if( (dirEntry > 0) && (errno == 0) ){
			if( strcmp( dirEntry->d_name, expectedResult ) == 0 ){
				printPass( testName );
			}else{
				printFail( testName, "File name was not correct" );
			}
		}else{
			printFail( testName, "Call to readdir() failed" );
		}
	}else{
		printFail( testName, "Unable to open the directory" );
	}
}
void TestOutputLayer_Backward() {
  double epsilon = 1e-3;

  std::vector<double> values;
  values.push_back(1.0);
  values.push_back(1.0);
  values.push_back(-1.0);

  std::vector<double> output;
  output.push_back(-2.2);
  output.push_back(3.4);
  output.push_back(5.5);

  OutputLayer layer(values.size());
  layer.receiveInput(values);

  assert(layer.getSize() == 3);

  layer.computeGradient(output);
  
  assert(layer.getPartialDerivative(0) < 3.2/3 + epsilon &&
         layer.getPartialDerivative(0) > 3.2/3 - epsilon);
  assert(layer.getPartialDerivative(1) < -2.4/3 + epsilon &&
         layer.getPartialDerivative(1) > -2.4/3 - epsilon);
  assert(layer.getPartialDerivative(2) < -6.5/3 + epsilon &&
         layer.getPartialDerivative(2) > -6.5/3 - epsilon);

  printPass("TestOutputLayer_Backward()");
}
void TestWeightMatrix_Backward() {
  double epsilon = 1e-3;

  int n_outputs = 2;
  int n_inputs = 3;
  InputLayer input_layer(n_inputs);
  OutputLayer output_layer(n_outputs);

  WeightMatrix weights(input_layer, output_layer);
  weights.set(0, 0, 0.5);
  weights.set(1, 0, -2.0);
  weights.set(2, 0, 1.5);
  weights.set(0, 1, 1.0);
  weights.set(1, 1, 0.7);
  weights.set(2, 1, -1.0);
  weights.setBias(0, 0.8);
  weights.setBias(1, -0.3);

  std::vector<double> inputs;
  inputs.push_back(-2.0);
  inputs.push_back(1.0);
  inputs.push_back(3.0);
  input_layer.receiveInput(inputs);

  std::vector<double> transition = weights.fire(input_layer);
  output_layer.receiveInput(transition);

  assert(output_layer.getInput(0) == 2.3);
  assert(output_layer.getInput(1) == -4.6);

  // backpropagation step
  std::vector<double> actual_outputs;
  actual_outputs.push_back(1.0);
  actual_outputs.push_back(1.0);

  output_layer.computeGradient(actual_outputs);
  weights.computeGradient(input_layer, output_layer);

  assert(weights.getPartialDerivative(0, 0) > -1.3 - epsilon &&
         weights.getPartialDerivative(0, 0) < -1.3 + epsilon);
  assert(weights.getPartialDerivative(1, 0) > 0.65 - epsilon &&
         weights.getPartialDerivative(1, 0) < 0.65 + epsilon);
  assert(weights.getPartialDerivative(2, 0) > 1.95 - epsilon &&
         weights.getPartialDerivative(2, 0) < 1.95 + epsilon);

  assert(weights.getPartialDerivative(0, 1) > 5.6 - epsilon &&
         weights.getPartialDerivative(0, 1) < 5.6 + epsilon);
  assert(weights.getPartialDerivative(1, 1) > -2.8 - epsilon &&
         weights.getPartialDerivative(1, 1) < -2.8 + epsilon);
  assert(weights.getPartialDerivative(2, 1) > -8.4 - epsilon &&
         weights.getPartialDerivative(2, 1) < -8.4 + epsilon);

  assert(weights.getBiasPartialDerivative(0) < 0.65 + epsilon &&
         weights.getBiasPartialDerivative(0) > 0.65 - epsilon);
  assert(weights.getBiasPartialDerivative(1) < -2.8 + epsilon &&
         weights.getBiasPartialDerivative(1) > -2.8 - epsilon);

  printPass("TestWeightMatrix_Backward()");
}
/**
 * Open a file several times and close just some of them.
 * This is also a general test for multiple file descriptors
 * for the same file.
 **/
void close_multipleRefs(){
	const char* testName = "close_multipleRefs";
	int theFileCREAT = -1;
	int theFileWRONLY = -1;
	int theFileRDONLY = -1;
	int ret = 0;
	char bytesRead[ gBufSmall ];
	char bytesExpected[ gBufSmall ];
	memset( bytesRead, 0, gBufSmall );
	memset( bytesExpected, 0, gBufSmall );
	strcpy( bytesExpected, gData1 );
	
	// Create a file.
	theFileCREAT = open( testName, O_CREAT );
	theFileWRONLY = open( testName, O_WRONLY );
	theFileRDONLY = open( testName, O_RDONLY );

	ret = close( theFileCREAT );
	if( ret == 0 ){
		ret = write( theFileWRONLY, gData1, strlen( gData1 ) );
		if( ret == strlen( gData1 ) ){	
			ret = close( theFileWRONLY );
			if( ret == 0 ){
				ret = read( theFileRDONLY, bytesRead, strlen( gData1 ) );
				if( ret == strlen( gData1 ) ){
					ret = close( theFileRDONLY );
					if( ret == 0 ){
						// Now further access should fail.
						ret = close( theFileCREAT );
						if( (ret == -1) && (errno == EBADF) ){
							printPass( testName );
						}else{
							printFail( testName, "Expected final return of -1 and errno of EBADF" );
						}
					}else{
						printFail( testName, "Third close was not successful" );
					}
				}else{
					printFail( testName, "Read was not successful" );
				}
			}else{
				printFail( testName, "Second close was not successful" );
			}
		}else{
			printFail( testName, "Write was not successful" );
		}
	}else{
		printFail( testName, "First close was not successful" );
	}

	// Just in case...
	close( theFileWRONLY );
	close( theFileRDONLY );
}
/**
 * Unlink a file that does not exist.
 **/
void unlink_enoent(){
	const char* testName = "unlink_enoent";
	
	errno = 0;
	int ret = unlink( testName );
	
	if( (ret == -1) && (errno == ENOENT) ){
		printPass( testName );
	}else{
		printFail( testName, "Unlink should have failed" );
	}
}
Beispiel #9
0
void printPassResult()
{
	extern lua_State *L;
	char buf[128] = {0};
	char *station = (char *)getTableElement(L, "con", "STATION");
	printItemHead( station );
	
	sprintf(buf, "%s TEST ALL PASS.", station);
	printPass(buf);
	
	drawButtonPoweroff();

}
void TestOutputNode() {
  OutputNode output_node1;
  output_node1.receiveInput(3.0);
  assert(output_node1.getInput() == 3.0);
  assert(output_node1.getOutput() == 3.0);

  OutputNode output_node2;
  output_node2.receiveInput(-4.0);
  assert(output_node2.getInput() == -4.0);
  assert(output_node2.getOutput() == -4.0);

  printPass("TestOutputNode()");
}
void TestHiddenNode() {
  HiddenNode hidden_node1;
  hidden_node1.receiveInput(3.0);
  assert(hidden_node1.getInput() == 3.0);
  assert(hidden_node1.getOutput() == 3.0);

  HiddenNode hidden_node2;
  hidden_node2.receiveInput(-4.0);
  assert(hidden_node2.getInput() == -4.0);
  assert(hidden_node2.getOutput() == 0.0);

  printPass("TestHiddenNode()");
}
void TestInputNode() {
  InputNode input_node1;
  input_node1.receiveInput(2.0);
  assert(input_node1.getInput() == 2.0);
  assert(input_node1.getOutput() == 2.0);

  InputNode input_node2;
  input_node2.receiveInput(-2.0);
  assert(input_node2.getInput() == -2.0);
  assert(input_node2.getOutput() == -2.0);

  printPass("TestInputNode()");
}
/**
 * Trigger enoent.
 **/
void stat_enoent(){
	const char* testName = "stat_enoent";
	struct stat statbuf;
	int ret = -1;
	
	errno = 0;
	ret = stat( "stat_enoent_does_not_exist", &statbuf );
	
	if( (errno == ENOENT) && (ret == -1) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected ENOENT" );
	}
}
/**
 * Trigger ebadf
 **/
void fstat_ebadf(){
	const char* testName = "stat_ebadf";
	struct stat statbuf;
	int ret = -1;
	
	errno = 0;
	ret = fstat( -1, &statbuf );
	
	if( (errno == EBADF) && (ret == -1) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected EBADF" );
	}
}
void TestHiddenLayer_Backward() {
  double epsilon = 1e-3;

  int n_outputs = 2;
  int n_inputs = 3;
  HiddenLayer hidden_layer(n_inputs);
  OutputLayer output_layer(n_outputs);

  std::vector<double> hidden_values;
  hidden_values.push_back(-2.0);
  hidden_values.push_back(1.0);
  hidden_values.push_back(3.0);

  WeightMatrix weights(hidden_layer, output_layer);
  weights.set(0, 0, 0.5);
  weights.set(1, 0, -2.0);
  weights.set(2, 0, 1.5);
  weights.set(0, 1, 1.0);
  weights.set(1, 1, 0.7);
  weights.set(2, 1, -1.0);
  weights.setBias(0, 0.8);
  weights.setBias(1, -0.3);

  hidden_layer.receiveInput(hidden_values);
  std::vector<double> transition = weights.fire(hidden_layer);
  output_layer.receiveInput(transition);

  assert(output_layer.getInput(0) == 3.3);
  assert(output_layer.getInput(1) == -2.6);

  // backpropagation step
  std::vector<double> actual_outputs;
  actual_outputs.push_back(1.0);
  actual_outputs.push_back(1.0);

  output_layer.computeGradient(actual_outputs);
  weights.computeGradient(hidden_layer, output_layer);
  hidden_layer.computeGradient(weights, output_layer);

  assert(hidden_layer.getPartialDerivative(0) < 0.0 + epsilon &&
         hidden_layer.getPartialDerivative(0) > 0.0 - epsilon);
  assert(hidden_layer.getPartialDerivative(1) < -3.56 + epsilon &&
         hidden_layer.getPartialDerivative(1) > -3.56 - epsilon);
  assert(hidden_layer.getPartialDerivative(2) < 3.525 + epsilon &&
         hidden_layer.getPartialDerivative(2) > 3.525 - epsilon);

  printPass("TestHiddenLayer_Backward()");
}
/**
 * Trigger ebadf.
 **/
void fflush_ebadf(){
	const char* testName = "fflush_ebadf";
	FILE* pFile;
	
	// Write.
	pFile = fopen( testName, "w+" );
	fclose( pFile );
	errno = 0;
	int ret = fflush( pFile );
	
	if( (errno == EBADF) && (ret == EOF) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected EBADF and EOF" );
	}

}
Beispiel #17
0
void printPassResult()
{
	extern lua_State *L;
	char buf[128] = {0};
	char *station = (char *)getTableElement(L, "con", "STATION");
	printItemHead( station );
	
	sprintf(buf, "%s TEST ALL PASS.", station);
	printPass(buf);
	
	drawButtonFinish();
	
//	SDL_SignalEmit( button_leave, "clicked", NULL);	
	
//	drawButtonPoweroff();

}
Beispiel #18
0
int main() {
        /* initialize bare minimum game variables  */
        int seed = 101; // seed for game init
        int numPlayers = 2;     // number of players
        int kCards[10] = {adventurer, council_room, feast,      // kingdom cards
        gardens, mine, remodel, smithy, village, baron, great_hall};
        struct gameState gState;
        int r = initializeGame(numPlayers, kCards, seed, &gState);      // initialize a new game
        int s;  // exit status for function

        /* extra parameters specific to this function  */
        int currentPlayer;
        int card;

        /*  game state variables used by this function  */
        int num;

        /*  counter variables  */

        // test over all players
        for(currentPlayer = 0; currentPlayer < numPlayers; currentPlayer++){
            // test over different cards
            for(card = 0; card < 20; card += 3){
                // test over some quantities of the chosen card
                for(num = 0; num <= 9; num += 3){
                    memset(&gState, 23, sizeof(struct gameState));          // clear the game state
                    r = initializeGame(numPlayers, kCards, seed, &gState);  // initialize the game

                    // set add'l game variables
                    initCards(&gState, num, card, currentPlayer);

                    // call the function under test
                    s = fullDeckCount(currentPlayer, card, &gState);

                    if(s == num){
                        printPass();
                    }
                    else printFail();
                    printTest("correct total of cards returned", num, s);
                }
            }
        }

       return 0;
}
Beispiel #19
0
/* function that selection sorts the array */
void selectionSort( int array[], int length )
{
   int smallest; /* index of smallest element */
   int i, j; /* ints used in for loops */
    
   /* loop over length - 1 elements */
   for ( i = 0; i < length - 1; i++ ) {
      smallest = i; /* first index of remaining array */
        
      /* loop to find index of smallest element */
      for ( j = i + 1; j < length; j++ )
         if ( array[ j ] < array[ smallest ] )
            smallest = j;
                
      swap( array, i, smallest ); /* swap smallest element */
      printPass( array, length, i + 1, smallest ); /* output pass */
   } /* end for */
} /* end function selectionSort */
/**
 * Call stat() on a file that's larger than a block.
 **/
void stat_largeFile(){
	const char* testName = "stat_largeFile";
	char aBlock[ gBufBlockSize + 1 ];
	struct stat statbuf;
	int ret = 0;
	
	// Write one more byte than a block.
	memset( aBlock, 'a', gBufBlockSize );
	aBlock[ gBufBlockSize ] = 0;
	
	int theFile = open( testName, O_CREAT | O_RDWR );
	write( theFile, aBlock, gBufBlockSize + 1 );
	close( theFile );
	
	errno = 0;
	ret = stat( testName, &statbuf );
	
	if( (errno == 0) && (ret == 0) ){
		if( statbuf.st_mode == S_IFREG ){
			if( statbuf.st_nlink == 1 ){
				if( statbuf.st_blksize == gBufBlockSize ){
					if( statbuf.st_blocks == 2 ){
						if( statbuf.st_size == gBufBlockSize + 1 ){
							printPass( testName );
						}else{
							printFail( testName, "Expected size = 4097" );
						}							
					}else{
						printFail( testName, "Expected st_blocks = 2" );
					}
				}else{
					printFail( testName, "Expected st_blksize = 4096" );
				}
			}else{
				printFail( testName, "Expected st_nlink = 1" );
			}
		}else{
			printFail( testName, "Expected st_mode = S_IFREG" );
		}
	}else{
		printFail( testName, "Expected errno == 0 and ret == 0" );
	}
}
/**
 * Create a file, write, read.
 **/
void fflush_basic(){
	const char* testName = "fflush_basic";
	int ret = -1;
	int theFile = -1;
	FILE* pFile = 0;
	char bytesRead[ gBufLarge ];
	memset( bytesRead, 0, gBufLarge );
	
	// Write.
	pFile = fopen( testName, "w+" );
	fwrite( gData1, sizeof( char ), strlen( gData1 ), pFile );

	// Read what was written.
	theFile = open( testName, O_RDONLY );
	read( theFile, bytesRead, strlen( gData1 ) );
	close( theFile );

	if( strlen( bytesRead ) == 0 ){		
		// Flush.
		errno = 0;
		ret = fflush( pFile );

		if( (ret == 0) && (errno == 0) ){
			// Read what was written.
			theFile = open( testName, O_RDONLY );
			read( theFile, bytesRead, strlen( gData1 ) );
			close( theFile );
			if( strcmp( bytesRead, gData1 ) == 0 ){
				printPass( testName );
			}else{
				printFail( testName, "Flushed data was not correct" );
			}
		}else{
			printFail( testName, "Expected ret == 0 and errno == 0" );
		}
		
	}else{
		printFail( testName, "Looks like flushing already happened, so we cannot continue with this test" );
	}

	fclose( pFile );
}
/**
 * Basic test for SEEK_CUR.
 **/
void fseek_cur(){
	const char* testName = "fseek_cur";
	const char* bytesExpected = "abc0e";
	char bytesRead[ gBufSmall ];
	int ret = -1;
	
	memset( bytesRead, 0, gBufSmall );
	
	int theFile = open( testName, O_RDWR | O_CREAT, S_IRWXU );
	write( theFile, gData1, strlen( gData1 ) );
	close( theFile );
	
	FILE* filePtr = fopen( testName, "r+" );
	
	// Write 2 bytes, then fseek ahead 1 more.
	fwrite( gData1, 1, 2, filePtr );
	errno = 0;
	ret = fseek( filePtr, 1, SEEK_CUR );
	
	if( (ret == 0) && (errno == 0) ){
		// Write a character and verify.
		fwrite( gData2, 1, 1, filePtr );
		fflush( filePtr );
		
		theFile = open( testName, O_RDONLY );
		read( theFile, &bytesRead, strlen( gData1 ) + 1 );
		close( theFile );
		
		if( strcmp( bytesRead, bytesExpected ) == 0 ){
			printPass( testName );
		}else{
			//printf( "expected: %s, actual: %s\n", bytesExpected, bytesRead );
			printFail( testName, "Data did not match" );
		}
		
	}else{
		printFail( testName, "Expected 0" );
	}
	
	close( theFile );

}
/**
 * "A component of the path prefix is not a directory."
 **/
void unlink_enotdir(){
	const char* testName = "unlink_enotdir";
	const char* dir1Name = "unlink_enotdir";
	const char* fileName = "unlink_enotdir/foo";
	const char* dir2Name = "unlink_enotdir/foo/foodir";
	
	mkdir( dir1Name, 0777 );
	
	int theFile = open( fileName, O_RDWR | O_CREAT );
	close( theFile );
	
	errno = 0;
	int ret = unlink( dir2Name );
	
	if( (ret == -1) && (errno == ENOTDIR) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected ret == -1 and errno == ENOTDIR.  Fails due to ALC-400. (Fixed)" );
	}
}
/**
 * Trigger enotdir
 **/
void stat_enotdir(){
	const char* testName = "stat_enotdir";
	const char* dir1Name = "/stat_enotdir";
	const char* fileName = "/stat_enotdir/file";
	const char* dir2Name = "/stat_enotdir/file/subdir";
	struct stat statbuf;

	mkdir( dir1Name, 0777 );

	int theFile = open( fileName, O_RDWR | O_CREAT );
	close( theFile );

	errno = 0;
	int ret = stat( dir2Name, &statbuf );
		
	if( (errno == ENOTDIR) && (ret == -1) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected ENOTDIR and -1.  Fails due to ALC-410. (Fixed)" );
	}
}
Beispiel #25
0
/* function that insertion sorts the array */
void insertionSort( int array[], int length )
{
    int insert; /* temporary variable to hold element to insert */
    int i; /* int used in for loop */

    /* loop over length - 1 elements */
    for ( i = 1; i < length; i++ ) {
        int moveItem = i; /* initialize location to place element */
        insert = array[ i ];

        /* search for place to put current element */
        while ( moveItem > 0 && array[ moveItem - 1 ] > insert ) {
            /* shift element right one slot */
            array[ moveItem ] = array[ moveItem - 1 ];
            --moveItem;
        } /* end while */

        array[ moveItem ] = insert; /* place inserted element */
        printPass( array, length, i, moveItem );
    } /* end for */
} /* end function insertionSort */
/**
 * Close a file and try to reuse the fildes.
 **/
void close_basic(){
	const char* testName = "close_basic";
	int theFile = -1;
	int flags = -1;
	int writeRet = 0;
	
	// Create a file.
	flags = O_RDWR | O_CREAT;
	theFile = open( testName, flags );
	close( theFile );
	
	// Write
	errno = 0;
	writeRet = write( theFile, gData1, strlen( gData1 ) );
	
	if( (errno == EBADF) && (writeRet == -1) ){
		printPass( testName );
	}else{
		printFail( testName, "Expected EBADF and a return value of -1" );
	}
}
/**
 * Call fstat() on a file.
 **/
void fstat_file(){
	const char* testName = "fstat_file";
	char aBlock[ gBufBlockSize ];
	struct stat statbuf;
	int ret = 0;
	
	// Write 4095 a's followed by a null.
	memset( aBlock, 'a', gBufBlockSize - 1 );
	aBlock[ gBufBlockSize - 1 ] = 0;
	
	int theFile = open( testName, O_CREAT | O_RDWR );
	write( theFile, aBlock, gBufBlockSize );
	
	errno = 0;
	ret = fstat( theFile, &statbuf );
	
	if( (errno == 0) && (ret == 0) ){
		if( statbuf.st_mode == S_IFREG ){
			if( statbuf.st_nlink == 1 ){
				if( statbuf.st_blksize == gBufBlockSize ){
					if( statbuf.st_blocks == 1 ){
						printPass( testName );
					}else{
						printFail( testName, "Expected st_blocks = 1" );
					}
				}else{
					printFail( testName, "Expected st_blksize = 4096" );
				}
			}else{
				printFail( testName, "Expected st_nlink = 1" );
			}
		}else{
			printFail( testName, "Expected st_mode = S_IFREG" );
		}
	}else{
		printFail( testName, "Expected errno == 0 and ret == 0" );
	}
	
	close( theFile );	
}
/**
 * Basic test for SEEK_END.
 **/
void fseek_end(){
	const char* testName = "fseek_end";
	const char* bytesExpected = "abcd0";
	char bytesRead[ gBufSmall ];
	int ret = -1;
	
	memset( bytesRead, 0, gBufSmall );
	
	int theFile = open( testName, O_RDWR | O_CREAT, S_IRWXU );
	write( theFile, gData1, strlen( gData1 ) );
	close( theFile );
	
	FILE* filePtr = fopen( testName, "r+" );
	errno = 0;
	
	// Seek
	ret = fseek( filePtr, -1, SEEK_END );
	
	if( (ret == 0) && (errno == 0) ){
		// Write a character and verify.
		fwrite( gData2, 1, 1, filePtr );
		fflush( filePtr );

		theFile = open( testName, O_RDONLY );
		read( theFile, &bytesRead, strlen( gData1 ) );
		close( theFile );
		
		if( strcmp( bytesRead, bytesExpected ) == 0 ){
			printPass( testName );
		}else{
			printFail( testName, "Data did not match" );
		}
		
	}else{
		printFail( testName, "Expected 0" );
	}
	
	fclose( filePtr );
}
void TestWeightMatrix_Forward() {
  int n_outputs = 2;
  InputLayer input_layer(3);
  OutputLayer output_layer(n_outputs);

  WeightMatrix weights(input_layer, output_layer);
  weights.set(0, 0, 0.5);
  weights.set(1, 0, -2.0);
  weights.set(2, 0, 1.5);
  weights.set(0, 1, 1.0);
  weights.set(1, 1, 0.7);
  weights.set(2, 1, -1.0);
  weights.setBias(0, 0.8);
  weights.setBias(1, -0.3);

  std::vector<double> inputs;
  inputs.push_back(-2.0);
  inputs.push_back(1.0);
  inputs.push_back(3.0);
  input_layer.receiveInput(inputs);

  std::vector<double> transition = weights.fire(input_layer);

  assert(transition.size() == 2);
  assert(transition[0] == 2.3);
  assert(transition[1] == -4.6);

  output_layer.receiveInput(transition);

  assert(output_layer.getInput(0) == 2.3);
  assert(output_layer.getInput(1) == -4.6);

  assert(output_layer.getOutput(0) == 2.3);
  assert(output_layer.getOutput(1) == -4.6);

  printPass("TestWeightMatrix_Forward()");
}
/**
 * Call stat() on a dir.
 **/
void stat_dir(){
	const char* testName = "stat_dir";
	const char* dirName = "/stat_dir";
	struct stat statbuf;
	int ret = 0;
	
	mkdir( dirName, 0777 );
	
	errno = 0;
	ret = stat( testName, &statbuf );
	
	if( (errno == 0) && (ret == 0) ){
		if( statbuf.st_mode == S_IFDIR ){
			if( statbuf.st_nlink == 1 ){
				if( statbuf.st_blksize == 4096 ){
					if( statbuf.st_blocks == 0 ){
						if( statbuf.st_size == 0 ){
							printPass( testName );
						}else{
							printFail( testName, "Expected size = 0" );
						}							
					}else{
						printFail( testName, "Expected st_blocks = 0" );
					}
				}else{
					printFail( testName, "Expected st_blksize = 4096" );
				}
			}else{
				printFail( testName, "Expected st_nlink = 1" );
			}
		}else{
			printFail( testName, "Expected st_mode = S_IFDIR" );
		}
	}else{
		printFail( testName, "Expected errno == 0 and ret == 0" );
	}
}