public void testReserveAndFree() throws Exception { Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i < TEST_ITERATIONS; ++i) { int trial = getTrial(rand); if (set.contains(trial)) { iAll.free(trial); set.remove(trial); } else { assertTrue("Did not reserve free integer " + trial, iAll.reserve(trial)); set.add(trial); } } for (int trial : set) { assertFalse("Integer " + trial + " not allocated!", iAll.reserve(trial)); } }
public void testAllocateAndFree() throws Exception { Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i < TEST_ITERATIONS; ++i) { if (getBool(rand)) { int trial = iAll.allocate(); assertFalse("Already allocated " + trial, set.contains(trial)); set.add(trial); } else { if (!set.isEmpty()) { int trial = extractOne(set); assertFalse("Allocator agreed to reserve " + trial, iAll.reserve(trial)); iAll.free(trial); } } } for (int trial : set) { assertFalse("Integer " + trial + " should be allocated!", iAll.reserve(trial)); } }