private void doPlusWithInts(int a, int b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(int.class, int.class)); Number n = plus.execute(a, b).as(Number.class); assert a + b == n.intValue() : "(" + a + " + " + b + ") = " + n.intValue(); }
private void doPlusWithShorts(int a, int b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(short.class, short.class)); Number n = plus.execute((short) a, (short) b).as(Number.class); assert a + b == n.intValue() : "(" + a + " + " + b + ") = " + n.intValue(); }
private void doPlusWithBytes(int a, int b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(byte.class, byte.class)); Number n = plus.execute((byte) a, (byte) b).as(Number.class); assert a + b == n.intValue() : "(" + a + " + " + b + ") = " + n.intValue(); }
private void doPlusWithLong(long a, long b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(long.class, long.class)); Number n = plus.execute(a, b).as(Number.class); assert a + b == n.longValue() : "(" + a + " + " + b + ") = " + n.longValue(); }
private void doPlusWithFloat(float a, float b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); Number n = plus.execute(a, b).as(Number.class); assertDouble("Correct value computed: (" + a + " + " + b + ")", a + b, n.floatValue()); }
private void doPlusWithDouble(double a, double b) throws Exception { PolyglotEngine.Value plus = findGlobalSymbol(plus(double.class, double.class)); Number n = plus.execute(a, b).as(Number.class); assertDouble("Correct value computed: (" + a + " + " + b + ")", a + b, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testPlusWithDoubleFloatSameAsInt() throws Exception { int x = RANDOM.nextInt(100); int y = RANDOM.nextInt(100); float a = x; float b = y; double u = a; double v = b; PolyglotEngine.Value floatPlus = findGlobalSymbol(plus(float.class, float.class)); PolyglotEngine.Value doublePlus = findGlobalSymbol(plus(double.class, double.class)); PolyglotEngine.Value intPlus = findGlobalSymbol(plus(int.class, int.class)); Number floatResult = floatPlus.execute(a, b).as(Number.class); Number doubleResult = doublePlus.execute(u, v).as(Number.class); Number intResult = intPlus.execute(x, y).as(Number.class); assertEquals("Correct value computed via int: (" + a + " + " + b + ")", x + y, intResult.intValue()); assertEquals("Correct value computed via float: (" + a + " + " + b + ")", intResult.intValue(), floatResult.intValue()); assertEquals("Correct value computed via double: (" + a + " + " + b + ")", intResult.intValue(), doubleResult.intValue()); }