import java.util.*;

class MapTest {
  static long seed = -1;
  static int num = 30;

  public static void main (String[] args) throws Throwable {
      final Random r = new Random(seed);

      // Test basic Map properties of TreeMap
      TreeMap tm = new TreeMap();
      checkMap(tm, r, num);
  }

  // Check basic Map properties
  static void checkMap(Map map, Random r, int num) throws Exception {
    // Fill in map
    for (int i = 0; i < num; i++) {
      int x = r.nextInt(num);
      map.put(new Integer(x), new Integer(i));
      checkSorted(map);
    }
  }

  // Check SortedMap properties
  static void checkSorted(Map map0) throws Exception {

      SortedMap map = (SortedMap)map0;
      Integer halfKey = new Integer(0);
      SortedMap map2 = map.tailMap(halfKey);

      // Removing this line makes it work.      
      SortedMap map3 = new TreeMap(map2);

      for (Iterator i = map2.entrySet().iterator(); i.hasNext(); ) {
	i.next();
      }

  }
}

/* Expected Output:
Checking class java.util.HashMap
Checking class java.util.TreeMap
*/

