package tests; import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.sql.Array; import org.junit.Test; import sysImplementation.Utilities; public class StudentTests { // how do I use assertions to test out all the // rotations? I've got everything being printed out // though. @Test public void testGetArrayString() { int[] testArrayStandardCase = { 1, 2, 3, 4, 5 }; int[] testArrayNullCase = null; int[] testArrayNoElements = {}; boolean isErrorThrown = false; //testing null case try { Utilities.getArrayString(testArrayNullCase, ','); } catch (IllegalArgumentException e) { isErrorThrown = true; } assertTrue(isErrorThrown); //testing no elements case String expectedResultNoElements = ""; assertEquals(expectedResultNoElements, Utilities.getArrayString(testArrayNoElements, ',')); // testing standard case String expectedResultStandardCase = "1+2+3+4+5"; assertEquals(expectedResultStandardCase, Utilities.getArrayString(testArrayStandardCase, '+')); // String outputStandardCase1 = Utilities.getArrayString(testArrayStandardCase, ' '); // System.out.println(outputStandardCase1); // // String outputStandardCase2 = Utilities.getArrayString(testArrayStandardCase, ','); // System.out.println(outputStandardCase2); // // String outputNullCase = Utilities.getArrayString(testArrayStandardCase, ','); // System.out.println(outputNullCase); } @Test public void testGetInstances() { int[] testArrayStandardCase = { 4, 5, 6, 77, 10000 }; int[] testArrayNullCase = null; // Testing Null Case boolean isErrorThrown = false; try { Utilities.getInstances(testArrayNullCase, 5, 6); } catch (IllegalArgumentException e) { isErrorThrown = true; } assertTrue(isErrorThrown); // Testing Standard Case, with lowerLimit and upperLimit inclusive int expectedResultStandardCase = 3; assertEquals(expectedResultStandardCase, Utilities.getInstances(testArrayStandardCase, 4, 6)); // System.out.println(outputStandardCase); // System.out.println(outputNullCase); } @Test public void testFilter() { int[] testArrayStandardCase = { 4, 50, 6, 10000, 8448 }; int[] testArrayNullCase = null; boolean errorIsThrown = false; int[] expectedResultStandardCase = {4, 50, 6}; assertArrayEquals(expectedResultStandardCase, Utilities.filter(testArrayStandardCase, 0, 50)); try { Utilities.filter(testArrayNullCase, 0, 100); } catch (IllegalArgumentException e) { errorIsThrown = true; } assertTrue(errorIsThrown); } @Test public void testRotate() { // Testing the null case int[] testArrayNullCase = null; boolean isErrorThrown = false; try { Utilities.rotate​(testArrayNullCase, true, 5); //why is this underlined here but not below? } catch (IllegalArgumentException e) { isErrorThrown = true; } assertTrue(isErrorThrown); // If the length of the array is less than or equal to 2, then does rotate() just return the original array? int[] testArraySmallArrayCaseLength2 = {1, 2}; Utilities.rotate​(testArraySmallArrayCaseLength2, true, 3); int[] comparisonArray = {1, 2}; assertArrayEquals(testArraySmallArrayCaseLength2, comparisonArray); // If leftRotation is true, then does rotate() rotate the array to the left? int[] testArrayStandardCase = { 10, 20, 7, 8}; int[] expectedResultRotateLeft = { 7, 8, 10, 20}; Utilities.rotate​(testArrayStandardCase, true, 2); assertArrayEquals(expectedResultRotateLeft, testArrayStandardCase); // If leftRotation is false, then does rotate() rotate the array to the left? int[] expectedResultRotateRight = {10, 20, 7, 8}; Utilities.rotate​(testArrayStandardCase, false, 2); assertArrayEquals(expectedResultRotateRight, testArrayStandardCase); } @Test public void testGetArrayStringsLongerThan() { // Testing the null case StringBuffer[] testArrayNullCase = null; boolean isErrorThrown = false; try { Utilities.getArrayStringsLongerThan​(testArrayNullCase, 0); } catch (IllegalArgumentException e) { isErrorThrown = true; } assertTrue(isErrorThrown); StringBuffer[] testArray = new StringBuffer[10]; testArray[0] = new StringBuffer(""); for (int i = 1; i < testArray.length; i++) { testArray[i] = new StringBuffer(testArray[i - 1].toString() + "a"); } StringBuffer[] result = Utilities.getArrayStringsLongerThan​(testArray, 5); assertTrue(result[0].toString().length()>5); for (int i = 0; i < result.length; i++) { System.out.println(result[i]); } } }