announcements‎ > ‎

2016-01-06 Testing Methods

posted Jan 6, 2016, 9:31 AM by Samuel Konstantinovich   [ updated Jan 6, 2016, 9:35 AM ]
public class Driver2{
    public static void main(String[]args){
        int size = 10000;
        String choice = "insertion";
        String order = "random"; // reversed sorted

        if(args.length >= 1){
            choice = args[0];
        }

        if(args.length >= 2){ //pick number of elements
            size = Integer.parseInt(args[1]);
        }

        if(args.length > 2){
            order = args[2];
        }
        int[]ary = new int[size];


        //default is random order
        Sorts.fillRandom(ary);
        if(order.equals("random")){

        }
        if(order.equals("sorted")){
            Arrays.sort(ary);
        }
        if(order.equals("reversed")){
            Arrays.sort(ary);
            for(int i = 0; i < ary.length / 2; i++){
                Sorts.swap(ary,i,ary.length-i-1);
            }
        }

        long start = System.currentTimeMillis();

        if(choice.equals("bubble")){
            Sorts.bubbleSort(ary);
        }
        if(choice.equals("insertion")){
            Sorts.insertionSort(ary);
        }
        if(choice.equals("selection")){
            Sorts.selectionSort(ary);
        }
        long end = System.currentTimeMillis();

        System.out.println("Time:"+ (end-start)/1000.0 + " seconds. Size = "+ary.length);
    }
}








echo ----------------
echo -Insertion
echo ---insertion random
java Driver2 insertion 20000 random
java Driver2 insertion 40000 random
java Driver2 insertion 80000 random
echo ---insertion sorted
java Driver2 insertion 20000 sorted
java Driver2 insertion 40000 sorted
java Driver2 insertion 80000 sorted
echo ---insertion reversed
java Driver2 insertion 20000 reversed
java Driver2 insertion 40000 reversed
java Driver2 insertion 80000 reversed
echo ----------------
echo -Selection
echo ---selection random
java Driver2 selection 20000 random
java Driver2 selection 40000 random
java Driver2 selection 80000 random
echo ---selection sorted
java Driver2 selection 20000 sorted
java Driver2 selection 40000 sorted
java Driver2 selection 80000 sorted
echo ---selection reversed
java Driver2 selection 20000 reversed
java Driver2 selection 40000 reversed
java Driver2 selection 80000 reversed
Comments