SHARE
TWEET

Untitled

a guest Dec 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *
  3.  */
  4. package server;
  5.  
  6. import static org.junit.Assert.*;
  7.  
  8. import java.rmi.RemoteException;
  9. import java.util.Arrays;
  10. import java.util.Random;
  11.  
  12. import org.junit.Before;
  13. import org.junit.Test;
  14.  
  15. /**
  16.  * @author Samuel van Oostveen
  17.  *
  18.  */
  19. @SuppressWarnings("rawtypes")
  20. public class BubbleSortTest {
  21.     ISorter sorter;
  22.     Comparable[] testArray;
  23.     Comparable[] testArray2;
  24.    
  25.     @Before
  26.     public void setUp() throws RemoteException
  27.     {
  28.         sorter = new BubbleSort();
  29.        
  30.         testArray = new Comparable[10000];
  31.         Random random = new Random();
  32.         for(int count = 0; count < testArray.length; count++) {
  33.             testArray[count] = random.nextInt(100000)-500000;
  34.         }
  35.         testArray2 = testArray.clone();
  36.         Arrays.sort(testArray2);
  37.     }
  38.    
  39.     /**
  40.      * Test method for {@link server.BubbleSort#sort(java.lang.Comparable[])}.
  41.      * @throws RemoteException
  42.      */
  43.     @Test
  44.     public void testRandomInteger() throws RemoteException {
  45.         assertArrayEquals(testArray2, sorter.sort( testArray));
  46.     }
  47.     @Test
  48.     public void testIntegerArray() throws RemoteException {
  49.         assertArrayEquals(new Comparable[]{2,3,6,230}, sorter.sort( new Comparable[]{2,3,6,230}));
  50.         assertArrayEquals(new Comparable[]{2,3,6}, sorter.sort( new Comparable[]{6,3,2}));
  51.     }
  52.     @Test
  53.     public void testStringArray() throws RemoteException {
  54.         assertArrayEquals(new Comparable[]{"hallo","test","w"}, sorter.sort( new Comparable[]{"hallo", "test", "w"}));
  55.         assertArrayEquals(new Comparable[]{"hallo", "test", "w"}, sorter.sort( new Comparable[]{"test","hallo","w"}));
  56.     }
  57.     @Test
  58.     public void testEmptyArray() throws RemoteException {
  59.         assertArrayEquals(new Comparable[]{}, sorter.sort( new Comparable[]{}) );
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top