### Question:
History { public boolean used( int k ) { if (k == 0) throw new IllegalArgumentException( "k == 0" ); int newUsed = used + k; if (newUsed > limit) return false; if (newUsed < 0) throw new IllegalStateException( "newUsed < 0" ); used = newUsed; bump( used ); return true; } History( int min, int limit, int len ); int limit(); int min(); int length(); boolean used( int k ); int getUsed(); void alloc( int k ); int getAlloc(); void init(); void tickle(); int suggested();  }### Answer:
@Test public void used1() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); assertTrue( h.used( 1 ) ); checkUsedAlloc( h, 1, 0 ); assertTrue( h.used( -1 ) ); checkUsedAlloc( h, 0, 0 ); }
@Test public void used2() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); assertTrue( h.used( 2 ) ); checkUsedAlloc( h, 2, 0 ); assertTrue( h.used( -2 ) ); checkUsedAlloc( h, 0, 0 ); }
@Test public void used3() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); assertTrue( h.used( 1 ) ); checkUsedAlloc( h, 1, 0 ); assertTrue( h.used( 1 ) ); checkUsedAlloc( h, 2, 0 ); assertTrue( h.used( -1 ) ); checkUsedAlloc( h, 1, 0 ); assertTrue( h.used( -1 ) ); checkUsedAlloc( h, 0, 0 ); }
@Test public void used4() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); assertFalse( h.used( 11 ) ); checkUsedAlloc( h, 0, 0 ); }
@Test public void used5() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); assertTrue( h.used( 1 ) ); checkUsedAlloc( h, 1, 0 ); assertTrue( h.used( 9 ) ); checkUsedAlloc( h, 10, 0 ); assertFalse( h.used( 1 ) ); checkUsedAlloc( h, 10, 0 ); }
@Test( expected = IllegalStateException.class ) public void used6() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); h.used( -1 ); }
@Test( expected = IllegalStateException.class ) public void used7() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); h.used( 1 ); checkUsedAlloc( h, 1, 0 ); h.used( -2 ); }
@Test public void used8() throws Exception { History h = new History( 0, 10, 5 ); checkUsedAlloc( h, 0, 0 ); h.used( 1 ); checkUsedAlloc( h, 1, 0 ); try { h.used( -2 ); fail( "never reached" ); } catch ( IllegalStateException e ) { checkUsedAlloc( h, 1, 0 ); } }
@Test( expected = IllegalArgumentException.class ) public void used9() throws Exception { History h = new History( 0, 10, 5 ); h.used( 0 ); }