MCPcopy Create free account
hub / github.com/CCCshengjiang/algorithm / main

Method main

data-structure-algorithm/src/cn/cwblue/heap/Heap.java:111–150  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

109 }
110
111 public static void main(String[] args) {
112 // 写对数器验证堆结构
113 int value = 1000;
114 int limit = 100;
115 int testTimes = 1000000;
116 for (int i = 0; i < testTimes; i++) {
117 int curLimit = (int)(Math.random() * limit) + 1;
118 RightMaxHeap test = new RightMaxHeap(curLimit);
119 MyMaxHeap my = new MyMaxHeap(curLimit);
120 int curOpTimes = (int)(Math.random() * limit);
121 for (int j = 0; j < curOpTimes; j++) {
122 if (my.isEmpty() != test.isEmpty()) {
123 System.out.println("Oops!");
124 }
125 if (my.isFull() != test.isFull()) {
126 System.out.println("Oops!");
127 }
128 if (my.isEmpty()) {
129 int curValue = (int)(Math.random() * value);
130 my.push(value);
131 test.push(value);
132 }else if (my.isFull()) {
133 if(my.pop() != test.pop()) {
134 System.out.println("Oops!");
135 }
136 }else {
137 if(Math.random() < 0.5) {
138 int curValue = (int)(Math.random() * value);
139 my.push(value);
140 test.push(value);
141 }else {
142 if(my.pop() != test.pop()) {
143 System.out.println("Oops!");
144 }
145 }
146 }
147 }
148 }
149 System.out.println("Finish!");
150 }
151}

Callers

nothing calls this directly

Calls 8

isEmptyMethod · 0.95
isEmptyMethod · 0.95
isFullMethod · 0.95
isFullMethod · 0.95
pushMethod · 0.95
pushMethod · 0.95
popMethod · 0.95
popMethod · 0.95

Tested by

no test coverage detected