Skip to content

Commit

Permalink
Fix PdfTextArray#add(float) number sum logic
Browse files Browse the repository at this point in the history
DEVSIX-7393
  • Loading branch information
dmitry.radchuk committed Mar 2, 2023
1 parent c4ecd12 commit 9521edf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public boolean add(float number) {
set(size() - 1, new PdfNumber(lastNumber));
} else {
remove(size() - 1);
lastNumber = Float.NaN;
}
} else {
lastNumber = number;
Expand Down
33 changes: 33 additions & 0 deletions kernel/src/test/java/com/itextpdf/kernel/pdf/PdfTextArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,37 @@ public void addCollectionTest() {
textArray.addAll(collection);
Assert.assertEquals(collection.list, textArray.list);
}

@Test
public void addZeroSumTest() {
PdfTextArray textArray = new PdfTextArray();
textArray.add(new PdfString("test"));
textArray.add(new PdfNumber(11));
textArray.add(new PdfNumber(12));
textArray.add(new PdfNumber(-13));
textArray.add(new PdfNumber(8));
textArray.add(new PdfNumber(-18));
textArray.add(new PdfString("test"));

PdfArray expected = new PdfArray();
expected.add(new PdfString("test"));
expected.add(new PdfString("test"));
Assert.assertEquals(expected.list, textArray.list);
}

@Test
public void addZeroSumAtTheBeginningTest() {
PdfTextArray textArray = new PdfTextArray();
textArray.add(new PdfNumber(11));
textArray.add(new PdfNumber(-11));
textArray.add(new PdfNumber(13));
textArray.add(new PdfString("test"));

PdfArray expected = new PdfArray();
expected.add(new PdfNumber(13));
expected.add(new PdfString("test"));
Assert.assertEquals(expected.list, textArray.list);
}


}

0 comments on commit 9521edf

Please sign in to comment.