public class MTDictVerifier {
  static boolean good= true;

  public static void main(String[] args) throws Exception {
    MTDict dict= new MTDict();
    Thread t1= new QueryThread(dict, "dog", "animal");
    Thread t2= new QueryThread(dict, "john", "human");
    Thread t3= new QueryThread(dict, "fly", "insect");

    Thread.sleep(1000);
    dict.addDef("dog", "animal");
    t1.join();

    Thread.sleep(1000);
    dict.addDef("fly", "insect");
    t3.join();

    Thread.sleep(1000);
    dict.addDef("john", "human");
    t2.join();

    if (good)
      System.out.println("Good! Your dictionary works properly");
    else
      System.err.println("Sorry, your dictionary does not work properly");
  }

  static class QueryThread extends Thread {
    MTDict dict;
    String key, def;
    QueryThread(MTDict dict, String key, String def) {
      this.dict= dict;
      this.key= key;
      this.def= def;
      start();
    }

    public void run() {
      String dictDef= dict.query(key);
      if (dictDef==null || !dictDef.equals(def)) {
        System.err.println( "query("+key+") should return "+def+
                            ", not "+dictDef );
        good= false;
      }
    }
  }
}
