Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class EvenSpread {
- public static void main(String[] args) {
- //Input
- //# of test cases vs # of modified transitions traversed for each test case
- int [][]testSuite = {
- {0,0,0,0,0,0,0},
- {0,0,1,1,0,0,0},
- {1,0,0,0,0,0,1},
- {0,0,1,0,1,0,0},
- {0,0,1,0,1,1,0},
- {0,1,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,1,0,0},
- {0,0,1,0,1,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,1,0,1,0,0}
- };
- //get # of test cases and # of modified transitions from testSuite array
- final int NUM_OF_MODIFIEDTRANSITION = testSuite[0].length;
- final int NUM_OF_TC = testSuite.length;
- //for storing prioritized ordering
- ArrayList<String> ordering = new ArrayList<String>();
- //for storing test cases with at least one modified transition
- ArrayList<Integer> TCWithModifiedTransition = new ArrayList<Integer>();
- //for storing modified transition with the least execution count for a particular iteration
- ArrayList<Integer> ModifiedTransitionWithLeastExecution = new ArrayList<Integer>();
- //for storing the value of the least execution count
- int min;
- //Initialize modified transition execution count and set to zero
- int[] modifiedTransitionExecution = new int[NUM_OF_MODIFIEDTRANSITION];
- for (int i = 0; i < modifiedTransitionExecution.length; i++)
- modifiedTransitionExecution[i] = 0;
- //Identify and store info of test cases with at least one modified transition
- for (int i = 0; i < NUM_OF_TC; i++)
- for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
- if (testSuite[i][j] == 1)
- {
- TCWithModifiedTransition.add(i);
- break;
- }
- //Print all test cases with modified transition
- System.out.println("----------------------------------------");
- System.out.println("Remaining test case = ");
- for(int word : TCWithModifiedTransition)
- System.out.print(word + " ");
- System.out.println("");
- //prioritize test cases containing modified transitions until all are selected
- while (!TCWithModifiedTransition.isEmpty())
- {
- //needs to be reset because in next iteration the lowest value might increase
- min = 100;
- //Update the modified transition with least execution number
- for (int i = 0; i < NUM_OF_MODIFIEDTRANSITION; i++)
- if (modifiedTransitionExecution[i] < min)
- min = modifiedTransitionExecution[i];
- //needs to be cleared because each iteration it may changes
- ModifiedTransitionWithLeastExecution.clear();
- //Put modified transitions with least execution into an arraylist
- for (int i = 0; i < NUM_OF_MODIFIEDTRANSITION; i++)
- if (modifiedTransitionExecution[i] == min)
- ModifiedTransitionWithLeastExecution.add(i);
- int k = 0, m = 0;
- while ( k < TCWithModifiedTransition.size() )
- {
- if (testSuite[TCWithModifiedTransition.get(k)][ModifiedTransitionWithLeastExecution.get(m)] == 1)
- {
- //put selected test case into prioritized ordering
- ordering.add(TCWithModifiedTransition.get(k).toString());
- //increase execution count of modified transition traversed in selected test case
- for (int l = 0; l < NUM_OF_MODIFIEDTRANSITION; l++)
- if (testSuite[TCWithModifiedTransition.get(k)][l] == 1)
- modifiedTransitionExecution[l] += 1;
- System.out.println("----------------------------------------");
- System.out.println("remove test case " + TCWithModifiedTransition.get(k));
- //remove selected test case from arraylist
- TCWithModifiedTransition.remove(k);
- for (int i = 0; i < modifiedTransitionExecution.length; i++)
- System.out.print("MT" + i + "=" + modifiedTransitionExecution[i] + ", ");
- System.out.println("");
- System.out.print("Remaining test case = ");
- for(int word : TCWithModifiedTransition)
- System.out.print(word + " ");
- System.out.println("");
- break;
- }
- k++;
- //if no test case traverse current modified transition with least execution,
- //move to next modified transition with least execution
- if (k == TCWithModifiedTransition.size())
- {
- m++;
- k = 0;
- }
- //if no more test case traverse the least executed modified transition,
- //move to next least executed modified transition
- if (m == ModifiedTransitionWithLeastExecution.size())
- {
- m = 0;
- k = 0;
- min += 1;
- //Put modified transitions with new least execution into an arraylist
- for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
- if (modifiedTransitionExecution[j] == min)
- ModifiedTransitionWithLeastExecution.add(j);
- }
- }
- }
- //Put remaining test cases into ordering
- for (int i = 0; i < NUM_OF_TC; i++)
- for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
- {
- if (testSuite[i][j] == 1)
- break;
- if (j == (NUM_OF_MODIFIEDTRANSITION-1) && testSuite[i][j] == 0)
- ordering.add(Integer.toString(i));
- }
- //Output
- System.out.print("Prioritized ordering = ");
- for(String word : ordering)
- System.out.print(word + " ");
- }
Add Comment
Please, Sign In to add comment