Vocabulary implements Iterable<String>, Serializable { public Double frequency(String word) { return this.count(word).doubleValue() / this.size.doubleValue(); } Vocabulary();  Vocabulary(List<String> words); void add(String word); void addAll(List<String> words); void limitWords(Integer maxWords); Integer count(String word); Double frequency(String word); Boolean contains(String word); Integer wordCount(); Integer totalCount(); @Override Iterator<String> iterator(); Set<String> wordSet(); @Override String toString();  }
@Test public void testFrequency() { Vocabulary vocabulary = new Vocabulary(); vocabulary.add("only one"); vocabulary.add("we are 2"); vocabulary.add("we are 2"); vocabulary.add("I like kitten"); assertEquals(0.25, vocabulary.frequency("only one"), 0.001); assertEquals(0.5, vocabulary.frequency("we are 2"), 0.001); assertEquals(0.0, vocabulary.frequency("I'm not here"), 0.001); }