/* * Joseph Ryan * jbr2558 * 16200 * Fall 2018 */ package assignment1; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import org.junit.Test; public class SampleTest { @Test(timeout = 2000) public void testIsSorted() { int[] x = new int[]{-2, -2, 0, 0, 2, 1}; assert (SortTools.isSorted(x, 0)); assert (SortTools.isSorted(x, 1)); assert (SortTools.isSorted(x, 2)); assert (SortTools.isSorted(x, 5)); assertFalse(SortTools.isSorted(x, 6)); } @Test(timeout = 2000) public void testFind() { int[] x = new int[]{-2, -1, 0, 1, 2, 3}; assertEquals(3, SortTools.find(x, 6, 1)); assertEquals(-1, SortTools.find(x, 6, 5)); assertEquals(0, SortTools.find(x, 1, -2)); assertEquals(1, SortTools.find(x, 2, -1)); } @Test(timeout = 2000) public void testInsertGeneral() { int[] x = new int[]{10, 20, 30, 40, 50}; int[] expected = new int[]{10, 20, 30, 35}; assertArrayEquals(expected, SortTools.insertGeneral(x, 3, 35)); expected = new int[]{1, 10}; assertArrayEquals(expected, SortTools.insertGeneral(x, 1, 1)); expected = new int[]{10, 11}; assertArrayEquals(expected, SortTools.insertGeneral(x, 1, 11)); expected = new int[]{1, 10, 20, 30, 40, 50}; assertArrayEquals(expected, SortTools.insertGeneral(x, 5, 1)); expected = new int[]{10, 20, 30, 40, 50, 1000}; assertArrayEquals(expected, SortTools.insertGeneral(x, 5, 1000)); } @Test(timeout = 2000) public void testInsertInPlace() { int[] x = new int[]{1, 2, 1000}; int[] expected = new int[]{1, 2, 3}; assertEquals(3, SortTools.insertInPlace(x, 2, 3)); assertArrayEquals(expected, x); } @Test(timeout = 2000) public void testSort() { int[] x = new int[]{6, 1, 2, 8, 9, 3, 0, 5, 4, 7}; int[] y = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; SortTools.insertSort(x, x.length); assertArrayEquals(y, x); } }