@Test public void doubleDivisionWithTwoRegistersEqualsExpected() { double value1 = 1586.2D; double value2 = 2536.9D; double expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "D"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "D"); buildInstruction12x(Opcode.DIV_DOUBLE); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(ARG1_REGISTER), eq(expected), eq("D")); }
@Test public void floatDivisionWithTwoRegistersEqualsExpected() { float value1 = 1120403456.43F; float value2 = 1149239296.32F; float expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "F"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "F"); buildInstruction12x(Opcode.DIV_FLOAT); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(ARG1_REGISTER), eq(expected), eq("F")); }
@Test public void intDivisionWithLiteralEqualsExpected() { int value1 = 10; int value2 = 4; int expected = value1 / value2; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "I"); buildInstruction22s(Opcode.DIV_INT, value2); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(DEST_REGISTER), eq(expected), eq("I")); }
@Test public void longDivisionWithThreeArgumentsAndResultLessThanOneEqualsZero() { long value1 = 1120403456L; long value2 = 1149239296L; long expected = value1 / value2; // 0 since long division drops decimal value VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "J"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "J"); buildInstruction23x(Opcode.DIV_LONG); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).assignRegister(eq(DEST_REGISTER), eq(expected), eq("J")); assertEquals("div-long r" + DEST_REGISTER + ", r" + ARG1_REGISTER + ", r" + ARG2_REGISTER, op.toString()); }
@Test public void longModuloByZeroExceptionIsCaughtAndHasNoChildrenAndAssignsNoRegisters() { long value1 = 1120403456L; long value2 = 0L; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "J"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "J"); buildInstruction23x(Opcode.REM_LONG); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); VMTester.verifyExceptionHandling(ArithmeticException.class, "/ by zero", node, mState); }
@Test public void longDivisionByZeroExceptionIsCaughtAndHasNoChildrenAndAssignsNoRegisters() { long value1 = 1120403456L; long value2 = 0L; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "J"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value2, "J"); buildInstruction23x(Opcode.DIV_LONG); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); VMTester.verifyExceptionHandling(ArithmeticException.class, "/ by zero", node, mState); }
@Test public void hasExpectedToStringValue() { int value = 0; VMTester.setRegisterMock(mState, ARG1_REGISTER, value, "D"); VMTester.setRegisterMock(mState, ARG2_REGISTER, value, "D"); instruction = buildInstruction22t(Opcode.IF_GE, 0); op = (IfOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); assertEquals("if-ge r2, r4, :addr_0", op.toString()); }
@Test public void integerModuloByZeroExceptionIsCaughtAndHasNoChildrenAndAssignsNoRegisters() { int value1 = 10; int value2 = 0; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "I"); buildInstruction22s(Opcode.REM_INT_LIT16, value2); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); VMTester.verifyExceptionHandling(ArithmeticException.class, "/ by zero", node, mState); }
@Test public void integerDivisionByZeroExceptionIsCaughtAndHasNoChildrenAndAssignsNoRegisters() { int value1 = 10; int value2 = 0; VMTester.setRegisterMock(mState, ARG1_REGISTER, value1, "I"); buildInstruction22s(Opcode.DIV_INT_LIT16, value2); op = opFactory.create(location, addressToLocation, vm); op.execute(node, mState); VMTester.verifyExceptionHandling(ArithmeticException.class, "/ by zero", node, mState); }