### Question:
ShortIndexManager implements Serializable { public ShortIndexManager() { nextIndex = 0; freeList = new ArrayList<Short>(); } ShortIndexManager(); short allocate(); void deallocate(short index); void clear();  }### Answer:
@Test public void testShortIndexManager() { ShortIndexManager imgr = new ShortIndexManager(); System.out.println("test basic allocation"); short index; for(short i=0;i<10;i++) { if ((index = imgr.allocate()) != i) { Assert.fail("Allocate: expected "+i+", and got "+index); } } System.out.println("test deallocation"); for(short i=5;i<8;i++) { imgr.deallocate(i); } for(short i = 7;i>=5;i--) { if ((index = imgr.allocate()) != i) { Assert.fail("Deallocate: expected "+i+", and got "+index); } } if (imgr.allocate() != 10) { Assert.fail("Deallocate: unexpected allocated index for 10"); } System.out.println("test clear all"); imgr.clear(); for(int i=0;i<10;i++) { if ((index = imgr.allocate()) != i) { Assert.fail("ClearAll: expected "+i+", and got "+index); } } }