java: adds Unpacker.unpackBigInteger()

This commit is contained in:
frsyuki 2010-08-19 01:19:34 +09:00
parent 1d17836b7d
commit b4c98584db
3 changed files with 55 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package org.msgpack;
import org.msgpack.*;
import java.io.*;
import java.util.*;
import java.math.BigInteger;
import org.junit.Test;
import static org.junit.Assert.*;
@ -48,6 +49,29 @@ public class TestDirectConversion {
assertEquals(val, pac.unpackLong());
}
@Test
public void testBigInteger() throws Exception {
testBigInteger(BigInteger.valueOf(0));
testBigInteger(BigInteger.valueOf(-1));
testBigInteger(BigInteger.valueOf(1));
testBigInteger(BigInteger.valueOf(Integer.MIN_VALUE));
testBigInteger(BigInteger.valueOf(Integer.MAX_VALUE));
testBigInteger(BigInteger.valueOf(Long.MIN_VALUE));
testBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
BigInteger max = BigInteger.valueOf(Long.MAX_VALUE).setBit(63);
testBigInteger(max);
Random rand = new Random();
for (int i = 0; i < 1000; i++)
testBigInteger( max.subtract(BigInteger.valueOf( Math.abs(rand.nextLong()) )) );
}
public void testBigInteger(BigInteger val) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
new Packer(out).pack(val);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
Unpacker pac = new Unpacker(in);
assertEquals(val, pac.unpackBigInteger());
}
@Test
public void testFloat() throws Exception {
testFloat((float)0.0);