/** * Simple test program. */ int main( ) { vector<int> a( 8 ); a[ 0 ] = 4; a[ 1 ] = -3; a[ 2 ] = 5; a[ 3 ] = -2; a[ 4 ] = -1; a[ 5 ] = 2; a[ 6 ] = 6; a[ 7 ] = -2; int maxSum; maxSum = maxSubSum1( a ); cout << "Max sum is " << maxSum << endl; maxSum = maxSubSum2( a ); cout << "Max sum is " << maxSum << endl; maxSum = maxSubSum3( a ); cout << "Max sum is " << maxSum << endl; maxSum = maxSubSum4( a ); cout << "Max sum is " << maxSum << endl; return 0; }
// Loads input file, runs maxSumSum2 algorithm on file contents, then outputs results to screen/output file. void testMaxSubSum2 (int tests, string fileID) { rTime cycleTime; vector<int> main; int totalTimeTaken = 0; string outputFile = "outputs/output_" + fileID + "_Algorithm2.txt"; ofstream output; output.open (outputFile.c_str (), ios::out); cout << "ALGORITHM 2 (maxSubSum2) TEST" << endl << "Input Size (n):" << fileID << endl; output << "ALGORITHM 2 (maxSubSum2) TEST" << endl << "Input Size (n):" << fileID << endl; for (int i = 0; i < tests; i++) { int maxSum = 0, timeTaken = 0; string temp = toString(i); cout << "Testing on File " << fileID << "_" << i << endl; main = loadFile (fileID, temp); const vector<int> *working = &main; cycleTime.resetStartTime(); maxSum = maxSubSum2(*working); timeTaken = cycleTime.getTimeElapsedMicro(); totalTimeTaken += timeTaken; cout << "File: " << fileID << "_" << i << ", Max Sum: " << maxSum << ", Time Taken: " << timeTaken << " Microseconds" << endl << endl; output << "File: " << fileID << "_" << i << ", Max Sum: " << maxSum << ", Time Taken: " << timeTaken << " Microseconds" << endl << endl; } cout << "Average Time: " << totalTimeTaken / tests << " Microseconds" << endl; output << "Average Time: " << totalTimeTaken / tests << " Microseconds" << endl; output.close(); }