mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
java: adds Packer.pack(<primitive types>)
This commit is contained in:
parent
40dc9de6c9
commit
48da2b8353
2 changed files with 89 additions and 38 deletions
|
|
@ -37,14 +37,30 @@ public class TestPackUnpack {
|
|||
testInt(rand.nextInt());
|
||||
}
|
||||
|
||||
public void testLong(long val) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new Packer(out).pack(val);
|
||||
MessagePackObject obj = unpackOne(out);
|
||||
assertEquals(val, obj.asLong());
|
||||
}
|
||||
@Test
|
||||
public void testLong() throws Exception {
|
||||
testLong(0);
|
||||
testLong(-1);
|
||||
testLong(1);
|
||||
testLong(Integer.MIN_VALUE);
|
||||
testLong(Integer.MAX_VALUE);
|
||||
testLong(Long.MIN_VALUE);
|
||||
testLong(Long.MAX_VALUE);
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
testLong(rand.nextLong());
|
||||
}
|
||||
|
||||
public void testBigInteger(BigInteger val) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
new Packer(out).pack(val);
|
||||
MessagePackObject obj = unpackOne(out);
|
||||
if(!val.equals(obj.asBigInteger())) {
|
||||
System.out.println("expect: "+val);
|
||||
System.out.println("but : "+obj.asBigInteger());
|
||||
}
|
||||
assertEquals(val, obj.asBigInteger());
|
||||
}
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue