+/EE422C

software design

git clone https://git.julia.blue/+/EE422C

Joseph RyanProject 1 and quiz 2ead272f

master
2.1 KiB66 linesraw
1/*
2 * Joseph Ryan
3 * jbr2558
4 * 16200
5 * Fall 2018
6 */
7
8package assignment1;
9
10import static org.junit.Assert.assertArrayEquals;
11import static org.junit.Assert.assertEquals;
12import static org.junit.Assert.assertFalse;
13
14import org.junit.Test;
15
16public class SampleTest {
17    @Test(timeout = 2000)
18    public void testIsSorted() {
19        int[] x = new int[]{-2, -2, 0, 0, 2, 1};
20        assert (SortTools.isSorted(x, 0));
21        assert (SortTools.isSorted(x, 1));
22        assert (SortTools.isSorted(x, 2));
23        assert (SortTools.isSorted(x, 5));
24        assertFalse(SortTools.isSorted(x, 6));
25    }
26
27    @Test(timeout = 2000)
28    public void testFind() {
29        int[] x = new int[]{-2, -1, 0, 1, 2, 3};
30        assertEquals(3, SortTools.find(x, 6, 1));
31        assertEquals(-1, SortTools.find(x, 6, 5));
32        assertEquals(0, SortTools.find(x, 1, -2));
33        assertEquals(1, SortTools.find(x, 2, -1));
34    }
35
36    @Test(timeout = 2000)
37    public void testInsertGeneral() {
38        int[] x = new int[]{10, 20, 30, 40, 50};
39        int[] expected = new int[]{10, 20, 30, 35};
40        assertArrayEquals(expected, SortTools.insertGeneral(x, 3, 35));
41        expected = new int[]{1, 10};
42        assertArrayEquals(expected, SortTools.insertGeneral(x, 1, 1));
43        expected = new int[]{10, 11};
44        assertArrayEquals(expected, SortTools.insertGeneral(x, 1, 11));
45        expected = new int[]{1, 10, 20, 30, 40, 50};
46        assertArrayEquals(expected, SortTools.insertGeneral(x, 5, 1));
47        expected = new int[]{10, 20, 30, 40, 50, 1000};
48        assertArrayEquals(expected, SortTools.insertGeneral(x, 5, 1000));
49    }
50
51    @Test(timeout = 2000)
52    public void testInsertInPlace() {
53        int[] x = new int[]{1, 2, 1000};
54        int[] expected = new int[]{1, 2, 3};
55        assertEquals(3, SortTools.insertInPlace(x, 2, 3));
56        assertArrayEquals(expected, x);
57    }
58
59    @Test(timeout = 2000)
60    public void testSort() {
61        int[] x = new int[]{6, 1, 2, 8, 9, 3, 0, 5, 4, 7};
62        int[] y = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
63        SortTools.insertSort(x, x.length);
64        assertArrayEquals(y, x);
65    }
66}