Skip to content
Snippets Groups Projects
Commit 01e6dbd3 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

test now uses guava to verify results

parent 64e9317c
No related branches found
No related tags found
No related merge requests found
......@@ -18,27 +18,44 @@ package teetime.stage;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
import teetime.framework.Analysis;
import teetime.stage.util.CountingMap;
import com.google.common.base.CharMatcher;
import com.google.common.base.Charsets;
import com.google.common.base.Splitter;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.io.Files;
public class WordCountingTest {
private final File testFile = new File("src/test/resources/data/output.txt");
private static final File testFile = new File("src/test/resources/data/output.txt");
@Test
public void test1() {
public void test1() throws IOException {
int threads = 6;
WordCountingConfiguration wcc = new WordCountingConfiguration(threads, testFile, testFile);
Analysis analysis = new Analysis(wcc);
analysis.start();
CountingMap<String> map = wcc.getResult();
assertEquals(new Integer(54), map.get("diam"));
assertEquals(new Integer(8), map.get("tation"));
assertEquals(new Integer(4), map.get("cum"));
assertEquals(new Integer(wordOccurrences(testFile).count(new String("diam")) * 2), map.get("diam"));
assertEquals(new Integer(wordOccurrences(testFile).count(new String("tation")) * 2), map.get("tation"));
assertEquals(new Integer(wordOccurrences(testFile).count(new String("cum")) * 2), map.get("cum"));
}
private Multiset<String> wordOccurrences(final File file) throws IOException {
return HashMultiset.create(
Splitter.on(CharMatcher.WHITESPACE)
.trimResults()
.omitEmptyStrings()
.split(Files.asCharSource(testFile, Charsets.UTF_8).read()));
}
}
// 56 et
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment