Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.StandardCharsets;
import org.apache.pulsar.common.util.SimpleTextOutputStream;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

@Test(groups = "utils")
Expand Down Expand Up @@ -104,6 +105,28 @@ public void testDoubleFormat() {
assertEquals(str(), "-123456.100");
}

@DataProvider
public Object[][] fractionalValues() {
return new Object[][] {
{-0.5, "-0.500"},
{-0.05, "-0.050"},
{-0.005, "-0.005"},
{-0.0005, "-0.0"},
{0.5, "0.500"},
{0.0005, "0.0"}
};
}

@Test(dataProvider = "fractionalValues")
public void testFractionalDoubleFormat(double value, String expected) {
try {
stream.write(value);
assertEquals(buf.toString(StandardCharsets.UTF_8), expected);
} finally {
buf.release();
}
}

@Test
public void testString() {
stream.writeEncoded("�\b`~�ýý8ýH\\abcd\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public SimpleTextOutputStream write(long n) {

public SimpleTextOutputStream write(double d) {
long i = (long) d;
if (d < 0 && i == 0) {
write('-');
}
write(i);

long r = Math.abs((long) (1000 * (d - i)));
Expand Down