MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / testRandom

Method testRandom

JSAT/test/jsat/utils/FibHeapTest.java:165–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163
164
165 @Test
166 public void testRandom()
167 {
168 System.out.println("testRandp,");
169 FibHeap<Long> heap = new FibHeap<Long>();
170
171 SortedMap<Long, Double> map = new TreeMap<Long, Double>();
172 Map<Long, FibHeap.FibNode<Long>> heapNodes = new HashMap<Long, FibHeap.FibNode<Long>>();
173
174 Random rand = RandomUtil.getRandom();
175
176 for(int trials = 0; trials < 10; trials++)
177 for(int maxSize = 1; maxSize < 2000; maxSize*=2)
178 {
179 while(map.size() < maxSize)
180 {
181
182 if(map.size() > 0 && rand.nextDouble() < 0.1)
183 {//ocasionally remove the min eliment
184 long entry = map.firstKey();
185 double value = map.get(entry);
186 for( Map.Entry<Long, Double> mapEntry : map.entrySet())
187 if(mapEntry.getValue() < value)
188 {
189 entry = mapEntry.getKey();
190 value = mapEntry.getValue();
191 }
192 map.remove(entry);
193
194 FibHeap.FibNode<Long> min = heap.removeMin();
195 heapNodes.remove(entry);
196
197 assertEquals(entry, min.value.longValue());
198 assertEquals(value, min.key, 0.0);
199
200 }
201 else if(map.size() > 0 && rand.nextDouble() < 0.4)
202 {//lest decrease a random key's value
203 long partitioner = rand.nextLong();
204 SortedMap<Long, Double> subMap = map.tailMap(partitioner);
205
206 long valToDecrease;
207 if(subMap.isEmpty())
208 {
209 subMap = map.headMap(partitioner);
210 valToDecrease = map.lastKey();
211 }
212 else
213 {
214 valToDecrease = map.firstKey();
215 }
216
217 double newVal = map.get(valToDecrease)/2;
218 map.put(valToDecrease, newVal);
219 heap.decreaseKey(heapNodes.get(valToDecrease), newVal);
220
221 }
222 //then add something

Callers

nothing calls this directly

Calls 14

getRandomMethod · 0.95
removeMinMethod · 0.95
decreaseKeyMethod · 0.95
insertMethod · 0.95
sizeMethod · 0.65
nextDoubleMethod · 0.45
getMethod · 0.45
entrySetMethod · 0.45
getValueMethod · 0.45
getKeyMethod · 0.45
removeMethod · 0.45
nextLongMethod · 0.45

Tested by

no test coverage detected