comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 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
comparison
equal deleted inserted replaced
22543:0ef597d27256 22544:9aded7e1e122
520 Number n = plus.execute(a, b).as(Number.class); 520 Number n = plus.execute(a, b).as(Number.class);
521 assert a + b == n.longValue() : "The value is correct: (" + a + " + " + b + ") = " + n.longValue(); 521 assert a + b == n.longValue() : "The value is correct: (" + a + " + " + b + ") = " + n.longValue();
522 } 522 }
523 523
524 @Test 524 @Test
525 public void testPlusWithDoubleFloatSameAsInt() throws Exception {
526 int x = RANDOM.nextInt(100);
527 int y = RANDOM.nextInt(100);
528 float a = x;
529 float b = y;
530 double u = a;
531 double v = b;
532
533 PolyglotEngine.Value floatPlus = findGlobalSymbol(plus(float.class, float.class));
534 PolyglotEngine.Value doublePlus = findGlobalSymbol(plus(double.class, double.class));
535 PolyglotEngine.Value intPlus = findGlobalSymbol(plus(int.class, int.class));
536
537 Number floatResult = floatPlus.execute(a, b).as(Number.class);
538 Number doubleResult = doublePlus.execute(a, b).as(Number.class);
539 Number intResult = intPlus.execute(a, b).as(Number.class);
540
541 assertEquals("Correct value computed via int: (" + a + " + " + b + ")", x + y, intResult.intValue());
542 assertEquals("Correct value computed via float: (" + a + " + " + b + ")", intResult.intValue(), floatResult.intValue());
543 assertEquals("Correct value computed via double: (" + a + " + " + b + ")", intResult.intValue(), doubleResult.intValue());
544 }
545
546 @Test
525 public void testPlusWithFloat() throws Exception { 547 public void testPlusWithFloat() throws Exception {
526 float a = RANDOM.nextFloat() * 100.0f; 548 float a = RANDOM.nextFloat() * 100.0f;
527 float b = RANDOM.nextFloat() * 100.0f; 549 float b = RANDOM.nextFloat() * 100.0f;
528 550
529 doPlusWithFloat(a, b); 551 doPlusWithFloat(a, b);