diff options
author | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-15 20:52:47 +0200 |
---|---|---|
committer | Maurice Laveaux <m.laveaux@student.tue.nl> | 2014-05-15 20:52:47 +0200 |
commit | a0fa8d9fb7aca060c4f525d3e92cba6d53242a95 (patch) | |
tree | 1699375774512629db317c011eba6c85162c531d /test | |
parent | d7c4a4ddb0b0fe43e5b02f1748c811a1249dd172 (diff) | |
download | Goldfarmer-a0fa8d9fb7aca060c4f525d3e92cba6d53242a95.tar.gz |
Added some basic test cases for BrandChecker.
Diffstat (limited to 'test')
-rw-r--r-- | test/analysis/BrandCheckerTest.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/analysis/BrandCheckerTest.java b/test/analysis/BrandCheckerTest.java new file mode 100644 index 0000000..06818ac --- /dev/null +++ b/test/analysis/BrandCheckerTest.java @@ -0,0 +1,86 @@ +package analysis; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author maurice + */ +public class BrandCheckerTest { + + public BrandCheckerTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Initialize the instance. + */ + private BrandChecker brandChecker; + + private void checkEquals(final List<String> expected, final List<String> results) { + for (String brand : expected) { + if (!results.contains(brand)) { + fail("expected brand " + brand + " was not in results " + results.toString()); + } + } + + for (String result : results) { + if (!expected.contains(result)) { + fail("unexpected brand " + result + " was not in the expected " + expected.toString()); + } + } + } + + public void doTest(final String input, final String[] expectedArray) { + brandChecker = new BrandChecker("brandrules.txt"); + + ArrayList<String> expected = new ArrayList(); + + expected.addAll(Arrays.asList(expectedArray)); + + List<String> results = brandChecker.getBrands(input); + + checkEquals(expected, results); + } + + @Test + public void testGetBrands() { + doTest("10 essential apps you need to install on your new Samsung Galaxy S5", new String[]{"galaxy s5"}); + } + + @Test + public void testMultiple() { + doTest("QBD - Black in Ear Earphones. 3.5mm Jack Plug for Apple iPod, " + + "IPhone 4, 4S, 5, 5S, 5C, Ipad Air, Ipad Mini", + new String[]{"iphone 4", "iphone 4s", "iphone 5S", "iphone 5c"}); + } + + @Test + public void testBullshit() { + doTest("This applepie is delicious", new String[]{}); + } + +} |