### Question:
RedBlackKeySet implements ShortKeySet, Serializable { public RedBlackKeySet(short n) { maxKey = n; } RedBlackKeySet(short n); int size(); boolean containsKey(short key); short getFirst(); short getLast(); short getNext(short key); short getPrevious(short key); void put(short key); boolean remove(short key); void removeAll(); boolean isEmpty(); static final int NODESIZE; }### Answer:
@Test public void testRedBlackKeySet() { System.out.println("Testing put method"); RedBlackKeySet bt = new RedBlackKeySet((short)1000); bt.put((short)25); bt.put((short)234); bt.put((short)2); bt.put((short)999); bt.put((short)0); bt.put((short)700); System.out.println("Testing first/next methods"); expect(bt, new int[]{0,2,25,234,700,999}); System.out.println("Testing last/previous methods"); expectBackwards(bt, new int[]{999,700,234,25,2,0}); System.out.println("Testing getNextMethod"); if (bt.getNext((short)500) != 700) { Assert.fail("Expected next value after 500 to be 700, but instead got"+bt.getNext((short)500)); } System.out.println("Testing delete"); bt.remove((short)234); bt.remove((short)2); bt.remove((short)999); expect(bt, new int[] {0,25,700}); System.out.println("Testing remove all"); bt.removeAll(); expect(bt, new int[]{}); System.out.println("Test putting all keys in set"); for(int i=0;i<1000;i++) { bt.put((short)i); } short n = bt.getFirst(); for(int i=0;i<1000;i++) { if (n != i) { Assert.fail("All keys failed! n = "+n+" and i = "+i); } n = bt.getNext(n); } if (n != -1) { Assert.fail("Too many keys in full RedBlackKeySet!"); } }