1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
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", "iphone 5"});
}
@Test
public void testBullshit() {
doTest("This applepie is delicious", new String[]{});
}
@Test
public void multipleBrands() {
doTest("This tweet contains both iphone 4s,galaxy s5 and iphone", new String[]{"iphone 4s", "galaxy s5"});
}
}
|