import java.io.*;
import java.util.*;
import java.lang.String.*;

/**
 *Test Case Generator by Jon Rathsam, Jonathan Koomjian, and Bevin Schneider
 *takes a file name of a test case file.
 *each new test case must be marked by a "####"
 *April 24, 2001
 */


public class TestGenerator2 {

    int i;
    String fileName;

    TestGenerator2 (String testFileName) {
        i = 1;
        fileName = testFileName;
    }

    //this is just a helper method that gets the length of the test case file
    public int getArrayLength(String fileName) {
	int count=0;
	int inChar=0;

	try {
	    FileReader file = new FileReader(fileName);
	    BufferedReader buff = new BufferedReader(file);

	    while (buff.read()!=-1) {
		count++;
	    } //while
	    buff.close();
   
	} catch (IOException e) {
	    System.out.println("error-" + e.toString());
	} //catch
    
	return count;

    } //getArrayLength

	



    //this is the program that gets and returns the test case.  It inputs a string fileName that is the name of the file and an int i that indicates which test case you want--eventually this will be automatic but for testing purposes it is imputted
    public String getTestCase() {
	int inChar=0;
	int y=0;
	int z=0;
	String output1 = new String();
	int arrayLength = getArrayLength(fileName);
	int[] array1 = new int[arrayLength];

//turn the .txt file into one huge array so it can be more easily worked with
	try {
	    FileReader file2 = new FileReader(fileName);
	    BufferedReader buff1 = new BufferedReader(file2);   
	    
	    for(int x=0; x < arrayLength; x++) {
		array1[x] = buff1.read(); 
	    } //for
	    buff1.close();
		} catch (IOException e) {
		    System.out.println("Error -- " + e.toString());
		}
	
	//find test cases in the array 
	  for (int x=0; y < i; x++) {
	      if (x>=array1.length) {
		z=-1;
		  break;
	      } else {		
	      if ((array1[x]==35)&&(array1[x+1]==35)&&(array1[x+2]==35)&&(array1[x+3]==35)){  //35= unicode for "#"
		  y++;  //a test case has been counted
		  z=x;	     
	      } else {
		  z=x; //so x can be used outside the loop
		  //x=x+3; when using "####"
	      } //else
	  }//else	
  } //for
	 
	  //output the correct test case   
if (z==-1) {
return "notestcases";
} else {	  
  boolean eof = false;
	    int j=z+4; //z+3 for "####"
	   
	    while (!eof){		
		if (j+1 >= array1.length || ((array1[j+1]==35)&&(array1[j+2]==35)&&(array1[j+3]==35)&&(array1[j+4]==35)))
		    eof = true;
		output1 +=( (char)array1[j] );
		j++ ;// System.out.print( (char)line );
	    } //while

	    i++;
	    return output1;
	   
}//else
  } //getTestCase
   } //class



