public static void main(String[] args) {

    // Run each test more than once to get bigger numbers and less noise.
    // You can try playing around with this number.
    int trials = 500;

    // The text to test on
    String dictFile = "/Users/mateusz/IdeaProjects/MOOCTextEditor/data/dict.txt";

    // The amount of words to increment each step
    // You can play around with this
    int increment = 2000;

    // The number of steps to run.
    // You can play around with this.
    int numSteps = 20;

    // The number of words to start with.
    // You can play around with this.
    int start = 50000;

    String notInDictionary = "notaword";

    // TODO: Play around with the numbers above and graph the output to see trends in the data
    for (int numToCheck = start;
        numToCheck < numSteps * increment + start;
        numToCheck += increment) {
      // Time the creation of finding a word that is not in the dictionary.
      DictionaryLL llDict = new DictionaryLL();
      DictionaryBST bstDict = new DictionaryBST();

      DictionaryLoader.loadDictionary(llDict, dictFile, numToCheck);
      DictionaryLoader.loadDictionary(bstDict, dictFile, numToCheck);

      long startTime = System.nanoTime();
      for (int i = 0; i < trials; i++) {
        llDict.isWord(notInDictionary);
      }
      long endTime = System.nanoTime();
      long timeLL = (endTime - startTime);

      startTime = System.nanoTime();
      for (int i = 0; i < trials; i++) {
        bstDict.isWord(notInDictionary);
      }
      endTime = System.nanoTime();
      long timeBST = (endTime - startTime);

      System.out.println(numToCheck + "\t" + timeLL + "\t" + timeBST);
    }
  }
示例#2
0
 protected char[][] dictionary() {
   try {
     loading.await();
   } catch (InterruptedException e) {
     Log.e("WordDictionary", "Loading is interrupted: ", e);
   }
   return loader.result();
 }
  /** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {
    emptyDict = new DictionaryLL();
    smallDict = new DictionaryLL();
    largeDict = new DictionaryLL();

    smallDict.addWord("Hello");
    smallDict.addWord("HElLo");
    smallDict.addWord("help");
    smallDict.addWord("a");
    smallDict.addWord("subsequent");

    DictionaryLoader.loadDictionary(largeDict, dictFile);
  }
示例#4
0
  public static void main(String[] args) {
    /* basic testing code to get started*/
    String word = "i";
    // Pass NearbyWords any Dictionary implementation you prefer
    Dictionary d = new DictionaryHashSet();
    DictionaryLoader.loadDictionary(d, "data/dict.txt");
    NearbyWords w = new NearbyWords(d);
    List<String> l = w.distanceOne(word, true);
    System.out.println("One away word Strings for for \"" + word + "\" are:");
    System.out.println(l + "\n");

    word = "tailo";
    List<String> suggest = w.suggestions(word, 10);
    System.out.println("Spelling Suggestions for \"" + word + "\" are:");
    System.out.println(suggest);
  }
  public static void main(String[] args) {
    int incorrect = 0;
    int tests = 0;
    String feedback = "";

    PrintWriter out;
    try {
      out = new PrintWriter("grader_output/module5.part3.out");
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    try {

      Dictionary dict = new DictionaryHashSet();
      DictionaryLoader.loadDictionary(dict, "data/grader_dict.txt");
      WPTree tree = new WPTree(new NearbyWords(dict));

      List<String> path = tree.findPath("pool", "spoon");

      feedback += "** Test #1: Testing short path...";
      feedback += "Your path was: " + printPath(path) + ".\n";

      path = tree.findPath("stools", "moon");

      feedback += "** Test #2: Testing long path...";
      feedback += "Your path was: " + printPath(path) + ".\n";

      path = tree.findPath("foal", "needless");

      feedback += "** Test #3: Testing impossible path...";
      feedback += "Your path was: " + printPath(path) + ".\n";

      path = tree.findPath("needle", "kitten");

      feedback += "** Test #4: Testing using a nonexistent word...";
      feedback += "Your path was: " + printPath(path) + ".\n";
    } catch (Exception e) {
      out.println(e);
      out.close();
      return;
    }

    out.println(feedback + "Tests complete. Make sure everything looks right.");
    out.close();
  }