-
Notifications
You must be signed in to change notification settings - Fork 429
/
TestProjectionProfile.java
110 lines (86 loc) · 2.81 KB
/
TestProjectionProfile.java
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package technology.tabula;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;
import org.junit.Before;
import org.junit.Test;
public class TestProjectionProfile {
ProjectionProfile pProfile;
Page page;
@Before
public void setUpProjectionProfile() {
PDPage pdPage = new PDPage();
PDDocument pdDocument = new PDDocument();
PDType1Font font = new PDType1Font(Standard14Fonts.FontName.HELVETICA);
TextElement textElement = new TextElement(5f, 15f, 10f, 20f, font, 1f, "test", 1f);
TextElement textElement2 = new TextElement(5f, 15f, 10f, 20f, font, 1f, "test", 1f);
List<TextElement> textList = new ArrayList<>();
textList.add(textElement);
textList.add(textElement2);
Ruling ruling = new Ruling(0, 0, 10, 10);
List<Ruling> rulingList = new ArrayList<>();
rulingList.add(ruling);
page = Page.Builder.newInstance()
.withPageDims(PageDims.of(0, 0, 1, 1))
.withRotation(0)
.withNumber(1)
.withPdPage(pdPage)
.withPdDocument(pdDocument)
.withTextElements(textList)
.withRulings(rulingList)
.build();
List<Rectangle> rectangles = new ArrayList<>();
rectangles.add(new Rectangle(0f, 0f, 500f, 5f));
pProfile = new ProjectionProfile(page, rectangles, 5, 5);
}
@Test
public void testGetVerticalProjection() {
float[] projection = pProfile.getVerticalProjection();
assertTrue(projection.length == 10);
}
@Test
public void testGetHorizontalProjection() {
float[] projection = pProfile.getHorizontalProjection();
assertTrue(projection.length == 10);
}
@Test
public void testFindVerticalSeparators() {
float[] seperators = pProfile.findVerticalSeparators(page.getText().size() * 2.5f);
assertTrue(seperators.length == 0);
}
@Test
public void testFindHorizontalSeparators() {
float[] seperators = pProfile.findHorizontalSeparators(page.getText().size() * 2.5f);
assertTrue(seperators.length == 0);
}
@Test
public void testSmooth() {
float[] data = {0, 1, 2};
float[] rv = ProjectionProfile.smooth(data, 3);
assertEquals(1f, rv[2], 1e-5);
}
@Test
public void testFilter() {
float[] data = {0, 1, 2};
float[] rv = ProjectionProfile.filter(data, 3);
assertEquals(3f, rv[1], 1e-5);
}
@Test
public void testGetAutocorrelation() {
float[] projection = {0, 1, 2};
float[] rv = ProjectionProfile.getAutocorrelation(projection);
assertEquals(0f, rv[0], 1e-5);
assertTrue(rv.length == 2);
}
@Test
public void testGetFirstDeriv() {
// float[]
// float[] projection = pProfile.getFirstDeriv(new float[]{0.0, 0.0)
// System.out.println(Arrays.toString(projection));
// assertEquals(10, projection[0], 1e-15);
}
}