/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityDouble() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); Number n = (Number) apply.execute(value).get(); assertDouble("The same value returned", value, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityFloat() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); Number n = (Number) apply.execute(value).get(); assertDouble("The same value returned", value, n.floatValue()); }
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 testPrimitiveidentityBoxedDouble() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); BoxedValue boxed = new BoxedValue(value); Number n = (Number) apply.execute(boxed).get(); assertDouble("The same value returned", value, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveidentityBoxedFloat() throws Exception { String id = identity(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); BoxedValue boxed = new BoxedValue(value); Number n = (Number) apply.execute(boxed).get(); assertDouble("The same value returned", value, n.floatValue()); }
/** @since 0.8 or earlier */ @Test public void readWriteFloatValue() throws Exception { String id = valuesObject(); ValuesObject values = findGlobalSymbol(id).execute().as(ValuesObject.class); assertDouble("Zero", 0, values.floatValue()); final float value = RANDOM.nextFloat() * 1000.0f; values.floatValue(value); assertDouble("Correct value", value, values.floatValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveReturnTypeFloat() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); Number n = apply.execute(fn).as(Number.class); assertDouble("The same value returned (" + value + " + 10): ", value + 10, n.floatValue()); }
/** @since 0.8 or earlier */ @Test public void testPrimitiveReturnTypeDouble() throws Exception { PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); Number n = apply.execute(fn).as(Number.class); assertDouble("The same value returned (" + value + " + 10): ", value + 10, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void readWriteDoubleValue() throws Exception { String id = valuesObject(); ValuesObject values = findGlobalSymbol(id).execute().as(ValuesObject.class); assertDouble("Zero", 0, values.doubleValue()); final double value = RANDOM.nextDouble() * 1000.0; values.doubleValue(value); assertDouble("Correct value", value, values.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testSumRealOfComplexNumbersA() throws Exception { String id = complexSumReal(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); ComplexNumbersA numbers = new ComplexNumbersA(new double[]{2, -1, 30, -1, 10, -1}); Number n = (Number) apply.execute(numbers).get(); assertDouble("The same value returned", 42.0, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testSumRealOfComplexNumbersB() throws Exception { String id = complexSumReal(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); ComplexNumbersB numbers = new ComplexNumbersB(new double[]{2, 30, 10}, new double[]{-1, -1, -1}); Number n = (Number) apply.execute(numbers).get(); assertDouble("The same value returned", 42.0, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testSumRealOfComplexNumbersAsStructuredDataColumnBased() throws Exception { String id = complexSumReal(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); Schema schema = new Schema(3, false, Arrays.asList(ComplexNumber.REAL_IDENTIFIER, ComplexNumber.IMAGINARY_IDENTIFIER), Arrays.asList(Type.DOUBLE, Type.DOUBLE)); byte[] buffer = new byte[6 * Double.SIZE / Byte.SIZE]; putDoubles(buffer, new double[]{2, 30, 10, -1, -1, -1}); StructuredData numbers = new StructuredData(buffer, schema); Number n = (Number) apply.execute(numbers).get(); assertDouble("The same value returned", 42.0, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testSumRealOfComplexNumbersAsStructuredDataRowBased() throws Exception { String id = complexSumReal(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); Schema schema = new Schema(3, true, Arrays.asList(ComplexNumber.REAL_IDENTIFIER, ComplexNumber.IMAGINARY_IDENTIFIER), Arrays.asList(Type.DOUBLE, Type.DOUBLE)); byte[] buffer = new byte[(6 * Double.SIZE / Byte.SIZE)]; putDoubles(buffer, new double[]{2, -1, 30, -1, 10, -1}); StructuredData numbers = new StructuredData(buffer, schema); Number n = (Number) apply.execute(numbers).get(); assertDouble("The same value returned", 42.0, n.doubleValue()); }
/** @since 0.8 or earlier */ @Test public void testAddComplexNumbersWithMethod() throws Exception { String id = complexAddWithMethod(); if (id == null) { return; } PolyglotEngine.Value apply = findGlobalSymbol(id); ComplexNumber a = new ComplexNumber(32, 10); ComplexNumber b = new ComplexNumber(10, 32); apply.execute(a, b); assertDouble("The same value returned", 42.0, a.get(ComplexNumber.REAL_IDENTIFIER)); assertDouble("The same value returned", 42.0, a.get(ComplexNumber.IMAGINARY_IDENTIFIER)); }
/** @since 0.8 or earlier */ @Test public void testEvaluateSource() throws Exception { Language language = vm().getLanguages().get(mimeType()); assertNotNull("Language for " + mimeType() + " found", language); PolyglotEngine.Value function = vm().findGlobalSymbol(evaluateSource()); assertNotNull(evaluateSource() + " found", function); double expect = Math.floor(RANDOM.nextDouble() * 100000.0) / 10.0; Object parsed = function.execute("application/x-tck", "" + expect).get(); assertTrue("Expecting numeric result, was:" + expect, parsed instanceof Number); double value = ((Number) parsed).doubleValue(); assertDouble("Gets the double", expect, value); }