Mercurial > hg > truffle
changeset 22544:9aded7e1e122
When integer values are on input of any language, the result should be the same regardless they are stored as int or float or double
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 07 Jan 2016 16:06:31 +0100 |
parents | 0ef597d27256 |
children | 17fe5ef92696 |
files | truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java Thu Jan 07 15:54:23 2016 +0100 +++ b/truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java Thu Jan 07 16:06:31 2016 +0100 @@ -522,6 +522,28 @@ } @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(a, b).as(Number.class); + Number intResult = intPlus.execute(a, b).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()); + } + + @Test public void testPlusWithFloat() throws Exception { float a = RANDOM.nextFloat() * 100.0f; float b = RANDOM.nextFloat() * 100.0f;