* Test method for {@link edu.buffalo.cse.ir.wikiindexer.tokenizer.TokenStream#getTokenMap()}.
*/
@Test
public void testGetTokenMap() {
//null string based stream
TokenStream stream = new TokenStream((String)null);
assertEquals(null, stream.getTokenMap());
stream = null;
//empty string
stream = new TokenStream("");
assertEquals(null, stream.getTokenMap());
stream = null;
//unique tokens
stream = new TokenStream("this");
stream.append("is", "a", "test", "string");
Map<String, Integer> smap = getSortedMap(stream.getTokenMap());
assertEquals("[a, is, string, test, this]", smap.keySet().toString());
assertEquals("[1, 1, 1, 1, 1]", smap.values().toString());
stream = null;
smap = null;
//same token repeated
stream = new TokenStream("hello");
stream.append("hello", "hello", "hello", "hello");
smap = getSortedMap(stream.getTokenMap());
assertEquals("[hello]", smap.keySet().toString());
assertEquals("[5]", smap.values().toString());
stream = null;
smap = null;
//combination
stream = new TokenStream("to");
stream.append("be", "or", "not", "to", "be");
smap = getSortedMap(stream.getTokenMap());
assertEquals("[be, not, or, to]", smap.keySet().toString());
assertEquals("[2, 1, 1, 2]", smap.values().toString());
stream = null;
smap = null;
//with remove
stream = new TokenStream("to");
stream.append("be", "or", "not", "to", "be");
stream.remove();
smap = getSortedMap(stream.getTokenMap());
assertEquals("[be, not, or, to]", smap.keySet().toString());
assertEquals("[2, 1, 1, 1]", smap.values().toString());
stream.seekEnd();
stream.previous(); //be
stream.previous(); //to
stream.remove();
stream.previous();
stream.remove();
smap = getSortedMap(stream.getTokenMap());
assertEquals("[be, or]", smap.keySet().toString());
assertEquals("[2, 1]", smap.values().toString());
stream = null;
smap = null;
//with merge with previous
stream = new TokenStream("to");
stream.append("be", "or", "not", "to", "be");
stream.next(); //at be
stream.mergeWithPrevious();
stream.seekEnd();
stream.previous();
stream.mergeWithPrevious();
smap = getSortedMap(stream.getTokenMap());
assertEquals("[not, or, to be]", smap.keySet().toString());
assertEquals("[1, 1, 2]", smap.values().toString());
stream = null;
//with merge with next
stream = new TokenStream("to");
stream.append("be", "or", "not", "to", "be");
stream.mergeWithNext();
stream.seekEnd();
stream.previous();
stream.previous();
stream.mergeWithNext();
smap = getSortedMap(stream.getTokenMap());
assertEquals("[not, or, to be]", smap.keySet().toString());
assertEquals("[1, 1, 2]", smap.values().toString());
stream = null;
}