import junit.framework.TestCase;

/**
 * A JUnit test case class.
 * Every method starting with the word "test" will be called when running
 * the test with JUnit.
 */
public class TestDemo extends TestCase {
    
    /**
     * A test method.
     * (Replace "X" with a name describing the test.  You may write as
     * many "testSomething" methods in this class as you wish, and each
     * one will be called when running JUnit over this class.)
     */
    public void testDutchNationalFlag() {
        int[] b= new int[] {1, 1, 1, 1, 1, 1};
        int[] ans= new int[] {1, 1, 1, 1, 1, 1};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
        b= new int[] {2, 2, 2, 2, 2, 2};
        ans= new int[] {2, 2, 2, 2, 2, 2};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
 
        b= new int[] {3, 3, 3, 3, 3};
        ans= new int[] {3, 3, 3, 3, 3};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
        b= new int[] {};
        ans= new int[] {};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
 
        b= new int[] {1, 1, 2, 2, 3, 3};
        ans= new int[] {1, 1, 2, 2, 3, 3};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {3, 2, 1, 3, 2, 1};
        ans= new int[] {1, 1, 2, 2, 3, 3};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {3, 3, 3, 1, 1, 1, 1};
        ans= new int[] {1, 1, 1, 1, 3, 3, 3};
        Demo.DutchFlag(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

    }
    
    public void testPartition() {
        int[] b= new int[] {1};
        int[] ans= new int[] {1};
        int j= Demo.partition(b, 0, 0);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        assertEquals(j, 0);
        
        b= new int[] {1, 2, 3, 4, 5};
        ans= new int[] {1, 3, 4, 5, 2};
        j= Demo.partition(b, 0, 4);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        assertEquals(j, 0);

        b= new int[] {3, 2, 1, 3, 4, 5};
        ans= new int[] {2, 1, 3, 3, 5, 4};
        j= Demo.partition(b, 0, 5);
        assertEquals(j, 3);
        assertEquals(Demo.toString(ans), Demo.toString(b));
 
        b= new int[] {6, 2, 1, 3, 4, 1};
        ans= new int[] {2, 1, 3, 4, 1, 6};
        j= Demo.partition(b, 0, 5);
        assertEquals(j, 5);
        assertEquals(Demo.toString(ans), Demo.toString(b));
   }
    
     public void testSelectionSort() {
        int[] b= new int[] {};
        int[] ans= new int[] {};
        Demo.selectionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {5};
        ans= new int[] {5};
        Demo.selectionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {1, 2, 3, 4, 8};
        ans= new int[] {1, 2, 3, 4, 8};
        Demo.selectionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {8, 6, 4, 2};
        ans= new int[] {2, 4, 6, 8};
        Demo.selectionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
        b= new int[] {8, 1, 6, 3, 4, 5, 2};
        ans= new int[] {1, 2, 3, 4, 5, 6, 8};
        Demo.selectionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
   }
     
     public void testPushDown() {
        int[] b= new int[] {5};
        int[] ans= new int[] {5};
        Demo.pushDown(b, 0);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {5, 7};
        ans= new int[] {5, 7};
        Demo.pushDown(b, 1);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {1, 2, 3, 4, 2};
        ans= new int[] {1, 2, 2, 3, 4};
        Demo.pushDown(b, 4);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {2, 3, 4, 5, 1, 6, 8};
        ans= new int[] {1, 2, 3, 4, 5, 6, 8};
        Demo.pushDown(b, 4);
        assertEquals(Demo.toString(ans), Demo.toString(b));
   }
     
      public void testInsertionSort() {
        int[] b= new int[] {};
        int[] ans= new int[] {};
        Demo.insertionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {5};
        ans= new int[] {5};
        Demo.insertionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {1, 2, 3, 4, 8};
        ans= new int[] {1, 2, 3, 4, 8};
        Demo.insertionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {8, 6, 4, 2};
        ans= new int[] {2, 4, 6, 8};
        Demo.insertionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
        b= new int[] {8, 1, 6, 3, 4, 5, 2};
        ans= new int[] {1, 2, 3, 4, 5, 6, 8};
        Demo.insertionSort(b);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
   }

      public void testQuickSort() {
        int[] b= new int[] {};
        int[] ans= new int[] {};
        Demo.quickSort(b, 0, b.length-1);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {5};
        ans= new int[] {5};
        Demo.quickSort(b, 0, b.length-1);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {1, 2, 3, 4, 8};
        ans= new int[] {1, 2, 3, 4, 8};
        Demo.quickSort(b, 0, b.length-1);
        assertEquals(Demo.toString(ans), Demo.toString(b));

        b= new int[] {8, 6, 4, 2};
        ans= new int[] {2, 4, 6, 8};
        Demo.quickSort(b, 0, b.length-1);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
        b= new int[] {8, 1, 6, 3, 4, 5, 2};
        ans= new int[] {1, 2, 3, 4, 5, 6, 8};
        Demo.quickSort(b, 0, b.length-1);
        assertEquals(Demo.toString(ans), Demo.toString(b));
        
   }
}
