forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestStringSearch.java
More file actions
93 lines (73 loc) · 2.74 KB
/
TestStringSearch.java
File metadata and controls
93 lines (73 loc) · 2.74 KB
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
92
93
package technology.tabula;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
import technology.tabula.detectors.StringSearch;
public class TestStringSearch {
@Test
public void testTwoString() {
try {
Page page = UtilsForTesting.getPage("src/test/resources/technology/tabula/wellExample_textBased.pdf", 1);
String[] inputs = new String[4];
inputs[0] = "Arsenic";
inputs[2] = "Zinc";
StringSearch stringSearch = new StringSearch();
List<Rectangle> stringRectangles = stringSearch.detect(page, inputs);
assertEquals(1, stringRectangles.size()); // check that table was found
Rectangle table = stringRectangles.get(0);
// check that found table is correct, within tolerance
assertTrue(Math.abs(table.height - 253) < 1);
assertTrue(Math.abs(table.width - 612) < 1);
assertTrue(Math.abs(table.x - 0) < 1);
assertTrue(Math.abs(table.y - 392.8) < 1);
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
public void testThreeString() {
try {
Page page = UtilsForTesting.getPage("src/test/resources/technology/tabula/wellExample_textBased.pdf", 1);
String[] inputs = new String[4];
inputs[0] = "Arsenic";
inputs[1] = "mg/L";
inputs[2] = "Zinc";
StringSearch stringSearch = new StringSearch();
List<Rectangle> stringRectangles = stringSearch.detect(page, inputs);
assertEquals(1, stringRectangles.size()); // check that table was found
Rectangle table = stringRectangles.get(0);
// check that found table is correct, within tolerance
assertTrue(Math.abs(table.height - 257.5) < 1);
assertTrue(Math.abs(table.width - 433) < 1);
assertTrue(Math.abs(table.x - 51.3) < 1);
assertTrue(Math.abs(table.y - 388.3) < 1);
} catch (IOException e) {
fail(e.getMessage());
}
}
@Test
public void testFourString() {
try {
Page page = UtilsForTesting.getPage("src/test/resources/technology/tabula/wellExample_textBased.pdf", 1);
String[] inputs = new String[4];
inputs[0] = "Arsenic";
inputs[1] = "mg/L";
inputs[2] = "Zinc";
inputs[3] = "mg/L";
StringSearch stringSearch = new StringSearch();
List<Rectangle> stringRectangles = stringSearch.detect(page, inputs);
assertEquals(1, stringRectangles.size()); // check that table was found
Rectangle table = stringRectangles.get(0);
// check that found table is correct, within tolerance
assertTrue(Math.abs(table.height - 257.5) < 1);
assertTrue(Math.abs(table.width - 433) < 1);
assertTrue(Math.abs(table.x - 51.3) < 1);
assertTrue(Math.abs(table.y - 388.3) < 1);
} catch (IOException e) {
fail(e.getMessage());
}
}
}