use of java.math.BigInteger in project j2objc by google.
the class BigIntegerTest method test_shiftRightI.
/**
* @tests java.math.BigInteger#shiftRight(int)
*/
public void test_shiftRightI() {
assertTrue("1 >> 0", BigInteger.valueOf(1).shiftRight(0).equals(BigInteger.ONE));
assertTrue("1 >> 1", BigInteger.valueOf(1).shiftRight(1).equals(BigInteger.ZERO));
assertTrue("1 >> 63", BigInteger.valueOf(1).shiftRight(63).equals(BigInteger.ZERO));
assertTrue("1 >> 64", BigInteger.valueOf(1).shiftRight(64).equals(BigInteger.ZERO));
assertTrue("1 >> 65", BigInteger.valueOf(1).shiftRight(65).equals(BigInteger.ZERO));
assertTrue("1 >> 1000", BigInteger.valueOf(1).shiftRight(1000).equals(BigInteger.ZERO));
assertTrue("-1 >> 0", BigInteger.valueOf(-1).shiftRight(0).equals(minusOne));
assertTrue("-1 >> 1", BigInteger.valueOf(-1).shiftRight(1).equals(minusOne));
assertTrue("-1 >> 63", BigInteger.valueOf(-1).shiftRight(63).equals(minusOne));
assertTrue("-1 >> 64", BigInteger.valueOf(-1).shiftRight(64).equals(minusOne));
assertTrue("-1 >> 65", BigInteger.valueOf(-1).shiftRight(65).equals(minusOne));
assertTrue("-1 >> 1000", BigInteger.valueOf(-1).shiftRight(1000).equals(minusOne));
BigInteger a = BigInteger.ONE;
BigInteger c = bi3;
BigInteger E = bi3.negate();
BigInteger e = E;
for (int i = 0; i < 200; i++) {
BigInteger b = BigInteger.ZERO.setBit(i);
assertTrue("a==b", a.equals(b));
a = a.shiftLeft(1);
assertTrue("a non-neg", a.signum() >= 0);
BigInteger d = bi3.shiftRight(i);
assertTrue("c==d", c.equals(d));
c = c.shiftRight(1);
assertTrue(">>1 == /2", d.divide(two).equals(c));
assertTrue("c non-neg", c.signum() >= 0);
BigInteger f = E.shiftRight(i);
assertTrue("e==f", e.equals(f));
e = e.shiftRight(1);
assertTrue(">>1 == /2", f.subtract(one).divide(two).equals(e));
assertTrue("e negative", e.signum() == -1);
assertTrue("b >> i", b.shiftRight(i).equals(one));
assertTrue("b >> i+1", b.shiftRight(i + 1).equals(zero));
assertTrue("b >> i-1", b.shiftRight(i - 1).equals(two));
}
}
use of java.math.BigInteger in project binnavi by google.
the class CInliningHelperTests method testCodeNodeStart.
@Test
public void testCodeNodeStart() {
// In this test we split a code node at its very first instruction
final CInstruction instruction1 = MockCreator.createInstructionWithOperand(new BigInteger("1234"), m_module, m_sql);
final CInstruction instruction2 = MockCreator.createInstructionWithOperand(new BigInteger("1235"), m_module, m_sql);
final CInstruction instruction3 = MockCreator.createInstructionWithOperand(new BigInteger("1236"), m_module, m_sql);
final INaviCodeNode codeNode1 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
final INaviCodeNode codeNode2 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
final INaviCodeNode codeNode3 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
m_view.getContent().createEdge(codeNode1, codeNode2, EdgeType.JUMP_CONDITIONAL_TRUE);
m_view.getContent().createEdge(codeNode2, codeNode3, EdgeType.JUMP_CONDITIONAL_FALSE);
CInliningHelper.inlineCodeNode(m_view, codeNode2, Iterables.get(codeNode2.getInstructions(), 0), m_function);
// The block is split + 5 nodes from the inlined function
assertEquals(2 + 1 + 5 + 1, m_view.getNodeCount());
final List<INaviViewNode> blocks = m_view.getGraph().getNodes();
final INaviCodeNode startNode = (INaviCodeNode) findStartNode(blocks);
assertEquals(1, Iterables.size(startNode.getInstructions()));
assertEquals(instruction1, Iterables.get(startNode.getInstructions(), 0));
assertEquals(1, startNode.getIncomingEdges().size());
assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, startNode.getIncomingEdges().get(0).getType());
assertEquals(1, startNode.getOutgoingEdges().size());
assertEquals(EdgeType.ENTER_INLINED_FUNCTION, startNode.getOutgoingEdges().get(0).getType());
final INaviViewNode firstInlinedNode = startNode.getOutgoingEdges().get(0).getTarget();
assertEquals(m_function.getAddress(), Iterables.get(((INaviCodeNode) firstInlinedNode).getInstructions(), 0).getAddress());
assertEquals(1, firstInlinedNode.getIncomingEdges().size());
assertEquals(1, firstInlinedNode.getOutgoingEdges().size());
final INaviViewNode middleInlinedNode = firstInlinedNode.getOutgoingEdges().get(0).getTarget();
assertEquals(2, middleInlinedNode.getIncomingEdges().size());
assertEquals(2, middleInlinedNode.getOutgoingEdges().size());
final INaviViewNode firstReturnNode = middleInlinedNode.getOutgoingEdges().get(0).getTarget();
final INaviViewNode secondReturnNode = middleInlinedNode.getOutgoingEdges().get(1).getTarget();
assertEquals(1, firstReturnNode.getIncomingEdges().size());
assertEquals(1, firstReturnNode.getOutgoingEdges().size());
assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, firstReturnNode.getOutgoingEdges().get(0).getType());
assertEquals(1, secondReturnNode.getIncomingEdges().size());
assertEquals(1, secondReturnNode.getOutgoingEdges().size());
assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, secondReturnNode.getOutgoingEdges().get(0).getType());
}
use of java.math.BigInteger in project binnavi by google.
the class CViewTest method testConstructor2.
@Test
public void testConstructor2() {
try {
new CView(new BigInteger(31, random).intValue(), (INaviProject) null, "Foo", "Bar", ViewType.Native, new Date(1234), new Date(12345), new MutableDirectedGraph<INaviViewNode, INaviEdge>(new ArrayList<INaviViewNode>(), new ArrayList<INaviEdge>()), new HashSet<CTag>(), false, new MockSqlProvider());
fail();
} catch (final NullPointerException e) {
}
final int viewId = new BigInteger(31, random).intValue();
final CView view = new CView(viewId, new MockProject(), "Foo", "Bar", ViewType.Native, new Date(1234), new Date(12345), new MutableDirectedGraph<INaviViewNode, INaviEdge>(new ArrayList<INaviViewNode>(), new ArrayList<INaviEdge>()), new HashSet<CTag>(), false, new MockSqlProvider());
assertEquals(viewId, view.getConfiguration().getId());
}
use of java.math.BigInteger in project binnavi by google.
the class CInliningHelperTests method testCodeNodeMiddle.
@Test
public void testCodeNodeMiddle() {
// In this test we split a code node right in the middle of the node
final CInstruction instruction1 = MockCreator.createInstructionWithOperand(new BigInteger("1234"), m_module, m_sql);
final CInstruction instruction2 = MockCreator.createInstructionWithOperand(new BigInteger("1235"), m_module, m_sql);
final CInstruction instruction3 = MockCreator.createInstructionWithOperand(new BigInteger("1236"), m_module, m_sql);
final INaviCodeNode codeNode1 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
final INaviCodeNode codeNode2 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
final INaviCodeNode codeNode3 = m_view.getContent().createCodeNode(m_function, Lists.newArrayList(instruction1, instruction2, instruction3));
m_view.getContent().createEdge(codeNode1, codeNode2, EdgeType.JUMP_CONDITIONAL_TRUE);
m_view.getContent().createEdge(codeNode2, codeNode3, EdgeType.JUMP_CONDITIONAL_FALSE);
CInliningHelper.inlineCodeNode(m_view, codeNode2, Iterables.get(codeNode2.getInstructions(), 1), m_function);
// The block is split + 5 nodes from the inlined function
assertEquals(2 + 1 + 5 + 1, m_view.getNodeCount());
assertEquals(2 + 5 + 2, m_view.getEdgeCount());
final List<INaviViewNode> blocks = m_view.getGraph().getNodes();
final INaviCodeNode startNode = (INaviCodeNode) findStartNode(blocks);
assertEquals(2, Iterables.size(startNode.getInstructions()));
assertEquals(instruction1, Iterables.get(startNode.getInstructions(), 0));
assertEquals(instruction2, Iterables.get(startNode.getInstructions(), 1));
assertEquals(1, startNode.getIncomingEdges().size());
assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, startNode.getIncomingEdges().get(0).getType());
assertEquals(1, startNode.getOutgoingEdges().size());
assertEquals(EdgeType.ENTER_INLINED_FUNCTION, startNode.getOutgoingEdges().get(0).getType());
final INaviViewNode firstInlinedNode = startNode.getOutgoingEdges().get(0).getTarget();
assertEquals(m_function.getAddress(), Iterables.get(((INaviCodeNode) firstInlinedNode).getInstructions(), 0).getAddress());
assertEquals(1, firstInlinedNode.getIncomingEdges().size());
assertEquals(1, firstInlinedNode.getOutgoingEdges().size());
final INaviViewNode middleInlinedNode = firstInlinedNode.getOutgoingEdges().get(0).getTarget();
assertEquals(2, middleInlinedNode.getIncomingEdges().size());
assertEquals(2, middleInlinedNode.getOutgoingEdges().size());
final INaviViewNode firstReturnNode = middleInlinedNode.getOutgoingEdges().get(0).getTarget();
final INaviViewNode secondReturnNode = middleInlinedNode.getOutgoingEdges().get(1).getTarget();
assertEquals(1, firstReturnNode.getIncomingEdges().size());
assertEquals(1, firstReturnNode.getOutgoingEdges().size());
assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, firstReturnNode.getOutgoingEdges().get(0).getType());
assertEquals(1, secondReturnNode.getIncomingEdges().size());
assertEquals(1, secondReturnNode.getOutgoingEdges().size());
assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, secondReturnNode.getOutgoingEdges().get(0).getType());
}
use of java.math.BigInteger in project guava by google.
the class UnsignedLongsTest method testToString.
public void testToString() {
String[] tests = { "ffffffffffffffff", "7fffffffffffffff", "ff1a618b7f65ea12", "5a4316b8c153ac4d", "6cf78a4b139a4e2a" };
int[] bases = { 2, 5, 7, 8, 10, 16 };
for (int base : bases) {
for (String x : tests) {
BigInteger xValue = new BigInteger(x, 16);
// signed
long xLong = xValue.longValue();
assertEquals(xValue.toString(base), UnsignedLongs.toString(xLong, base));
}
}
}
Aggregations