Guest User

Untitled

a guest
Feb 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.65 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class EvenSpread {
  4. public static void main(String[] args) {
  5.  
  6. //Input
  7. //# of test cases vs # of modified transitions traversed for each test case
  8. int [][]testSuite = {
  9. {0,0,0,0,0,0,0},
  10. {0,0,1,1,0,0,0},
  11. {1,0,0,0,0,0,1},
  12. {0,0,1,0,1,0,0},
  13. {0,0,1,0,1,1,0},
  14. {0,1,0,0,0,0,0},
  15. {0,0,0,0,0,0,0},
  16. {0,0,0,0,1,0,0},
  17. {0,0,1,0,1,0,0},
  18. {0,0,0,0,0,0,0},
  19. {0,0,0,0,0,0,0},
  20. {0,0,1,0,1,0,0}
  21. };
  22.  
  23. //get # of test cases and # of modified transitions from testSuite array
  24. final int NUM_OF_MODIFIEDTRANSITION = testSuite[0].length;
  25. final int NUM_OF_TC = testSuite.length;
  26.  
  27. //for storing prioritized ordering
  28. ArrayList<String> ordering = new ArrayList<String>();
  29.  
  30. //for storing test cases with at least one modified transition
  31. ArrayList<Integer> TCWithModifiedTransition = new ArrayList<Integer>();
  32.  
  33. //for storing modified transition with the least execution count for a particular iteration
  34. ArrayList<Integer> ModifiedTransitionWithLeastExecution = new ArrayList<Integer>();
  35.  
  36. //for storing the value of the least execution count
  37. int min;
  38.  
  39. //Initialize modified transition execution count and set to zero
  40. int[] modifiedTransitionExecution = new int[NUM_OF_MODIFIEDTRANSITION];
  41. for (int i = 0; i < modifiedTransitionExecution.length; i++)
  42. modifiedTransitionExecution[i] = 0;
  43.  
  44. //Identify and store info of test cases with at least one modified transition
  45. for (int i = 0; i < NUM_OF_TC; i++)
  46. for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
  47. if (testSuite[i][j] == 1)
  48. {
  49. TCWithModifiedTransition.add(i);
  50. break;
  51. }
  52.  
  53. //Print all test cases with modified transition
  54. System.out.println("----------------------------------------");
  55. System.out.println("Remaining test case = ");
  56. for(int word : TCWithModifiedTransition)
  57. System.out.print(word + " ");
  58.  
  59. System.out.println("");
  60.  
  61. //prioritize test cases containing modified transitions until all are selected
  62. while (!TCWithModifiedTransition.isEmpty())
  63. {
  64. //needs to be reset because in next iteration the lowest value might increase
  65. min = 100;
  66.  
  67. //Update the modified transition with least execution number
  68. for (int i = 0; i < NUM_OF_MODIFIEDTRANSITION; i++)
  69. if (modifiedTransitionExecution[i] < min)
  70. min = modifiedTransitionExecution[i];
  71.  
  72. //needs to be cleared because each iteration it may changes
  73. ModifiedTransitionWithLeastExecution.clear();
  74.  
  75. //Put modified transitions with least execution into an arraylist
  76. for (int i = 0; i < NUM_OF_MODIFIEDTRANSITION; i++)
  77. if (modifiedTransitionExecution[i] == min)
  78. ModifiedTransitionWithLeastExecution.add(i);
  79.  
  80. int k = 0, m = 0;
  81.  
  82. while ( k < TCWithModifiedTransition.size() )
  83. {
  84. if (testSuite[TCWithModifiedTransition.get(k)][ModifiedTransitionWithLeastExecution.get(m)] == 1)
  85. {
  86. //put selected test case into prioritized ordering
  87. ordering.add(TCWithModifiedTransition.get(k).toString());
  88.  
  89. //increase execution count of modified transition traversed in selected test case
  90. for (int l = 0; l < NUM_OF_MODIFIEDTRANSITION; l++)
  91. if (testSuite[TCWithModifiedTransition.get(k)][l] == 1)
  92. modifiedTransitionExecution[l] += 1;
  93.  
  94. System.out.println("----------------------------------------");
  95. System.out.println("remove test case " + TCWithModifiedTransition.get(k));
  96.  
  97. //remove selected test case from arraylist
  98. TCWithModifiedTransition.remove(k);
  99.  
  100. for (int i = 0; i < modifiedTransitionExecution.length; i++)
  101. System.out.print("MT" + i + "=" + modifiedTransitionExecution[i] + ", ");
  102. System.out.println("");
  103. System.out.print("Remaining test case = ");
  104. for(int word : TCWithModifiedTransition)
  105. System.out.print(word + " ");
  106. System.out.println("");
  107. break;
  108. }
  109.  
  110. k++;
  111.  
  112. //if no test case traverse current modified transition with least execution,
  113. //move to next modified transition with least execution
  114. if (k == TCWithModifiedTransition.size())
  115. {
  116. m++;
  117. k = 0;
  118. }
  119.  
  120. //if no more test case traverse the least executed modified transition,
  121. //move to next least executed modified transition
  122. if (m == ModifiedTransitionWithLeastExecution.size())
  123. {
  124. m = 0;
  125. k = 0;
  126. min += 1;
  127.  
  128. //Put modified transitions with new least execution into an arraylist
  129. for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
  130. if (modifiedTransitionExecution[j] == min)
  131. ModifiedTransitionWithLeastExecution.add(j);
  132. }
  133. }
  134. }
  135.  
  136. //Put remaining test cases into ordering
  137. for (int i = 0; i < NUM_OF_TC; i++)
  138. for (int j = 0; j < NUM_OF_MODIFIEDTRANSITION; j++)
  139. {
  140. if (testSuite[i][j] == 1)
  141. break;
  142. if (j == (NUM_OF_MODIFIEDTRANSITION-1) && testSuite[i][j] == 0)
  143. ordering.add(Integer.toString(i));
  144. }
  145.  
  146. //Output
  147. System.out.print("Prioritized ordering = ");
  148. for(String word : ordering)
  149. System.out.print(word + " ");
  150. }
Add Comment
Please, Sign In to add comment