DJimLut / Assignment5

A repository for Dr. Matthew Tennyson's Assignment 5 in CSC-445: Computer Algorithms
0 stars 0 forks source link

Exception thrown in radixSort #5

Closed djimenezmsu closed 1 year ago

djimenezmsu commented 1 year ago

I was writing some tests for the two methods and ran into this one:

java.lang.StringIndexOutOfBoundsException: String index out of range: 2
 at java.base/java.lang.StringLatin1.charAt([StringLatin1.java:47](vscode-file://vscode-app/e:/VSCode/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.lang.String.charAt([String.java:693](vscode-file://vscode-app/e:/VSCode/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at main.SortComparison.radixSort([SortComparison.java:34](vscode-file://vscode-app/e:/VSCode/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at tests.SortComparisonTests.radixSort5([SortComparisonTests.java:23](vscode-file://vscode-app/e:/VSCode/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))

Seems to be an indexing error with the charAt function call on line 34 of SortComparison.java.

djimenezmsu commented 1 year ago

Also, when testing heapSort it didn't end up actually sorting the array. Not sure why, but I tested with Arrays.sort() to be sure and it should be sorting the array. The array came out the same as it was passed.

djimenezmsu commented 1 year ago

Exception was thrown as expected because test was using differently sized strings in the same string array.