MCPcopy Index your code
hub / github.com/careercup/ctci / main

Method main

java/Chapter 9/Question9_3/QuestionB.java:52–68  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

50 }
51
52 public static void main(String[] args) {
53 for (int i = 0; i < 1000; i++) {
54 int size = AssortedMethods.randomIntInRange(5, 20);
55 int[] array = getSortedArray(size);
56 int v2 = magicFast(array);
57 if (v2 == -1 && magicSlow(array) != -1) {
58 int v1 = magicSlow(array);
59 System.out.println("Incorrect value: index = -1, actual = " + v1 + " " + i);
60 System.out.println(AssortedMethods.arrayToString(array));
61 break;
62 } else if (v2 > -1 && array[v2] != v2) {
63 System.out.println("Incorrect values: index= " + v2 + ", value " + array[v2]);
64 System.out.println(AssortedMethods.arrayToString(array));
65 break;
66 }
67 }
68 }
69
70}

Callers

nothing calls this directly

Calls 5

randomIntInRangeMethod · 0.95
getSortedArrayMethod · 0.95
magicFastMethod · 0.95
magicSlowMethod · 0.95
arrayToStringMethod · 0.95

Tested by

no test coverage detected