PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tests/gov/nasa/jpf/symbc/strings/performance/Performance01.java

https://bitbucket.org/chaceliang/jpf-symbc
Java | 143 lines | 128 code | 5 blank | 10 comment | 34 complexity | c3096442653755883e462023360e1e9a MD5 | raw file
  1. package gov.nasa.jpf.symbc.strings.performance;
  2. public class Performance01 {
  3. //MAX_LENGTH = 5 for all tests
  4. private static final int MAX_LENGTH = 10;
  5. public static void main (String [] args) {
  6. test2 ("dcba", "a", "b");
  7. }
  8. public static void test (String a, String b) {
  9. int i = 0;
  10. if (a.endsWith("a")) {
  11. System.out.println("Step 1");
  12. i++;
  13. }
  14. if (b.endsWith("b")) {
  15. System.out.println("Step 2");
  16. i++;
  17. }
  18. if (a.startsWith(b)) {
  19. System.out.println("Step 3");
  20. i++;
  21. }
  22. if (!a.equals(b)) {
  23. System.out.println("Step 4");
  24. i++;
  25. }
  26. if (a.trim().contains(b)) {
  27. System.out.println("Step 5");
  28. i++;
  29. }
  30. /*if (i == 5) {
  31. throw new RuntimeException ("look at this");
  32. }*/
  33. }
  34. public static void test2 (String a, String b, String c) {
  35. int i = 0;
  36. if (a.length () < MAX_LENGTH && b.length() < MAX_LENGTH && c.length() < MAX_LENGTH) {
  37. if (a.endsWith("a")) {
  38. System.out.println("Step 1");
  39. i++;
  40. }
  41. if (b.endsWith("b")) {
  42. System.out.println("Step 2");
  43. i++;
  44. }
  45. if (c.endsWith("c")) {
  46. System.out.println("Step 3");
  47. i++;
  48. }
  49. if (a.startsWith(b)) {
  50. System.out.println("Step 4");
  51. i++;
  52. }
  53. if (b.startsWith(c)) {
  54. System.out.println("Step 5");
  55. i++;
  56. }
  57. if (!a.equals(b)) {
  58. System.out.println("Step 6");
  59. i++;
  60. }
  61. if (!b.equals(c)) {
  62. System.out.println("Step 7");
  63. i++;
  64. }
  65. if (a.trim().contains(b)) {
  66. System.out.println("Step 8");
  67. i++;
  68. }
  69. if (b.trim().contains(c)) {
  70. System.out.println("Step 9");
  71. i++;
  72. }
  73. /*if (i == 9) {
  74. throw new RuntimeException ("look at this");
  75. }*/
  76. }
  77. }
  78. public static void test3 (String a, String b, String c, String d) {
  79. int i = 0;
  80. if (a.length () < MAX_LENGTH && b.length() < MAX_LENGTH && c.length() < MAX_LENGTH && d.length() < MAX_LENGTH) {
  81. if (a.endsWith("a")) {
  82. System.out.println("Step 1");
  83. i++;
  84. }
  85. if (b.endsWith("b")) {
  86. System.out.println("Step 2");
  87. i++;
  88. }
  89. if (c.endsWith("c")) {
  90. System.out.println("Step 3");
  91. i++;
  92. }
  93. if (d.endsWith("d")) {
  94. System.out.println("Step 4");
  95. i++;
  96. }
  97. if (a.startsWith(b)) {
  98. System.out.println("Step 5");
  99. i++;
  100. }
  101. if (b.startsWith(c)) {
  102. System.out.println("Step 6");
  103. i++;
  104. }
  105. if (c.startsWith(d)) {
  106. System.out.println("Step 7");
  107. i++;
  108. }
  109. if (!a.equals(b)) {
  110. System.out.println("Step 8");
  111. i++;
  112. }
  113. if (!b.equals(c)) {
  114. System.out.println("Step 9");
  115. i++;
  116. }
  117. if (!c.equals(d)) {
  118. System.out.println("Step 10");
  119. i++;
  120. }
  121. if (a.trim().contains(b)) {
  122. System.out.println("Step 11");
  123. i++;
  124. }
  125. if (b.trim().contains(c)) {
  126. System.out.println("Step 12");
  127. i++;
  128. }
  129. if (c.trim().contains(d)) {
  130. System.out.println("Step 13");
  131. i++;
  132. }
  133. /*if (i == 13) {
  134. throw new RuntimeException ("look at this");
  135. }*/
  136. }
  137. }
  138. }