ScheduleTest:
import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.*; public class ScheduleTest { Schedule s; Work a = new Work("a",1,3); Work b = new Work("b",2,2); Work c = new Work("c",3,2); Work d = new Work("d",3,1); List<Work> l,l2; @Before public void setup() { s = new Schedule(); l = new ArrayList<Work>(); l.add(a); l.add(b); l.add(c); l2 = new ArrayList<Work>(); l2.add(c); l2.add(b); l2.add(d); } @Test public void testFCFS() { List<Double> ll = new ArrayList<Double>(); ll.add(4.0);ll.add(1.8333333333333333); List<Double> ld = s.FCFS(l); Iterator<Double> j = ll.iterator(); for(Iterator<Double> i = ld.iterator();i.hasNext(); ){ assertEquals(j.next(),i.next()); } } @Test public void testSJF() { List<Double> ll = new ArrayList<Double>(); ll.add(2.6666666666666665);ll.add(1.6666666666666667); List<Double> ld = s.SJF(l2); Iterator<Double> j = ll.iterator(); for(Iterator<Double> i = ld.iterator();i.hasNext(); ){ assertEquals(j.next(),i.next()); } } @Test public void testGetPriority() { assertEquals(0,a.getPriority()); } }
SortingTest:
import static org.junit.Assert.*; import org.junit.*; public class SortingTest { Sorting s; @Before public void setup() { s = new Sorting(); } @Test public void testInsertionSort() { int [] an = {5,2,3,4,1}; assertEquals(false,s.isSorted(an)); s.insertionSort(an); assertEquals("whetherInsertSorted",true,s.isSorted(an)); } @Test public void testIsSorted() { int [] an = {1,2,3,4}; int [] bn = {1,4,3,2}; assertEquals("whetherSorted",true,s.isSorted(an)); assertEquals("whetherSorted",false,s.isSorted(bn)); } @Test public void testQuicksort() { int [] an = {9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1}; assertEquals(false,s.isSorted(an)); s.quicksort(an); assertEquals("whetherQuickSorted",true,s.isSorted(an)); } @Test public void testSwapReferences() { String [] an = {"1","2"}; String [] bn = {"2","1"}; s.swapReferences(an, 0, 1); assertEquals("whetherErrorSwap",bn,an); } }
TriangleTest:
import static org.junit.Assert.*; import org.junit.*; public class TriangleTest { Triangle a; Triangle b; Triangle c; Triangle d; Triangle e; @Before public void setup() { a = new Triangle(-1,1,2); b = new Triangle(1,2,3); c = new Triangle(2,2,2); d = new Triangle(2,2,3); e = new Triangle(2,3,4); } @Test public void testIsTriangle() { assertEquals(false,a.isTriangle(a)); assertEquals(false,b.isTriangle(b)); assertEquals(true,c.isTriangle(c)); } @Test public void testGetType() { assertEquals("Illegal",b.getType(b)); assertEquals("Regular",c.getType(c)); assertEquals("Isosceles",d.getType(d)); assertEquals("Scalene",e.getType(e)); } @Test public void testGetBorders() { long [] an = {-1,1,2}; long [] bn = a.getBorders(); assertEquals(an[0],bn[0]); assertEquals(an[1],bn[1]); assertEquals(an[2],bn[2]); } }