### Question:
NgramModel implements Serializable { public void addText(InputStream is) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String context = String.valueOf(BOS); while (reader.ready()) { String line = StringNormalizer.reduceWS(reader.readLine()); if (!line.isEmpty()) { String input = (context.charAt(0) == BOS) ? line : " " + line; addSubstrings(context, input); if (input.length() >= order) { context = input.substring(input.length() - order + 1); } else { String s = context + input; context = s.substring(Math.max(0, s.length() - order + 1)); } } } addSubstrings(context, String.valueOf(EOS)); } catch (FileNotFoundException ex) { Messages.severe(NgramModel.class.getName() + ": " + ex); } catch (IOException ex) { Messages.severe(NgramModel.class.getName() + ": " + ex); } } NgramModel(int order);  NgramModel(File file); int size(); void save(File file); double[] getGoodTuringPars(); int occurrences(String key); void addWord(String word); void addWords(File file, Charset encoding, boolean caseSensitive); double logWordProb(String word); double logPerWordLikelihood(boolean caseSensitive); void addText(InputStream is); double logLikelihood(InputStream is, int contextLength); double logLikelihood(String context, String input); double logProb(String context, char c); @Override String toString(); void showDiff(NgramModel other); boolean equals(NgramModel other); @Override boolean equals(Object o); @Override int hashCode(); static void main(String[] args);  }### Answer:
@Test public void testAddText() { System.out.println("addText"); String BOS = String.valueOf(NgramModel.BOS); String EOS = String.valueOf(NgramModel.EOS); NgramModel ngrams = new NgramModel(3); NgramModel ref = new NgramModel(3); String input = "ab\nc"; InputStream is = new ByteArrayInputStream(input.getBytes()); ngrams.addText(is); ref.addEntry(BOS + "ab"); ref.addEntry("ab "); ref.addEntry("b c"); ref.addEntry(" c" + EOS); ref.addEntry(BOS + 'a'); ref.addEntry("ab"); ref.addEntry("b "); ref.addEntry(" c"); ref.addEntry("c" + EOS); ref.addEntry("a"); ref.addEntry("b"); ref.addEntry(" "); ref.addEntry("c"); ref.addEntry(EOS); ref.addEntries("", 5); ref.showDiff(ngrams); assertEquals(ref, ngrams); String text = "ab"; is = new ByteArrayInputStream(text.getBytes()); double expectedResult = Math.log(0.2); double result = ngrams.logLikelihood(is, 0); assertEquals(expectedResult, result, 0.0001); }