private void removeAllocation(Allocation alloc) { removeAlert(alloc); if (allocations.contains(alloc)) { allocations.remove(alloc); tableModel.fireTableDataChanged(); } }
@Ignore public void testSize() { MyTreeSet test = new MyTreeSet(); test.add(1); test.add(2); test.add(3); test.add(1); // Size should be 3. System.out.println(test.size()); }
@Ignore public void testAddT() { MyTreeSet test = new MyTreeSet(); test.add(1); test.add(2); test.add(3); test.add(1); System.out.println(test.size()); }
@Ignore public void testIterator() { MyTreeSet test = new MyTreeSet(); test.add(1); test.add(2); test.add(3); test.add(1); Iterator<Integer> ls = test.iterator(); while (ls.hasNext()) { System.out.println(ls.next().toString()); } }
public static void main(String[] args) { Set<Integer> real = new TreeSet<Integer>(); MyTreeSet<Integer> fake = new MyTreeSet<Integer>(); while (real.size() < NUMBER_OF_ELEMENTS) { debug("real: " + real); debug("fake: " + fake); Integer value = new Integer(random(MAX_VALUE)); boolean realBool = real.contains(value); boolean fakeBool = fake.contains(value); if (fakeBool != realBool) throw new RuntimeException( "contains(" + value + ") returned " + fakeBool + " and should return " + realBool); // add debug("add(" + value + ")"); realBool = real.add(value); fakeBool = fake.add(value); if (fakeBool != realBool) throw new RuntimeException( "add(" + value + ") returned " + fakeBool + " and should return " + realBool); int realInt = real.size(); int fakeInt = fake.size(); if (realInt != fakeInt) throw new RuntimeException("size() returned " + fakeInt + " and should return " + realInt); } while (real.size() > 0) { debug("real: " + real); debug("fake: " + fake); Integer value = new Integer(random(MAX_VALUE)); boolean realBool = real.contains(value); boolean fakeBool = fake.contains(value); if (fakeBool != realBool) throw new RuntimeException( "contains(" + value + ") returned " + fakeBool + " and should return " + realBool); // remove debug("remove(" + value + ")"); realBool = real.remove(value); fakeBool = fake.remove(value); if (fakeBool != realBool) throw new RuntimeException( "remove(" + value + ") returned " + fakeBool + " and should return " + realBool); int realInt = real.size(); int fakeInt = fake.size(); if (realInt != fakeInt) throw new RuntimeException("size() returned " + fakeInt + " and should return " + realInt); } System.out.println("MyTreeSet works!"); }
private void checkAllocations(Enumeration en) { while (en.hasMoreElements()) { Allocation alloc = (Allocation) en.nextElement(); AllocationResult ar = alloc.getEstimatedResult(); if (ar != null) { if (!allocations.contains(alloc)) { allocations.add(alloc); tableModel.fireTableDataChanged(); } else { tableModel.fireTableDataChanged(); } if (ar.isSuccess()) { removeAlert(alloc); } else { createAlert(alloc); } } else { removeAllocation(alloc); } } }
@Test public void testClear() { MyTreeSet test = new MyTreeSet(); test.add(1); test.add(2); test.add(3); test.add(4); // Size should be 4 System.out.println(test.size()); test.clear(); // Size should be 0 System.out.println(test.size()); }
private Allocation[] getAllocationArray() { if (allocationArray == null) { allocationArray = (Allocation[]) allocations.toArray(new Allocation[allocations.size()]); } return allocationArray; }