Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/utilities/ExactClassValueProfileTest.java @ 22493:1cb72700c10e
Increase test coverage for ExactClassValueProfile class.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 12 Dec 2015 13:34:49 +0100 |
parents | b39b603e2a1e |
children |
comparison
equal
deleted
inserted
replaced
22492:bc3303fb3888 | 22493:1cb72700c10e |
---|---|
22 */ | 22 */ |
23 package com.oracle.truffle.api.utilities; | 23 package com.oracle.truffle.api.utilities; |
24 | 24 |
25 import static org.hamcrest.CoreMatchers.is; | 25 import static org.hamcrest.CoreMatchers.is; |
26 import static org.junit.Assert.assertEquals; | 26 import static org.junit.Assert.assertEquals; |
27 import static org.junit.Assert.assertNotNull; | |
27 import static org.junit.Assert.assertNull; | 28 import static org.junit.Assert.assertNull; |
28 import static org.junit.Assert.assertThat; | 29 import static org.junit.Assert.assertThat; |
29 | 30 |
30 import java.lang.reflect.Method; | 31 import java.lang.reflect.Method; |
31 | 32 |
42 @DataPoint public static final String O1 = new String(); | 43 @DataPoint public static final String O1 = new String(); |
43 @DataPoint public static final String O2 = new String(); | 44 @DataPoint public static final String O2 = new String(); |
44 @DataPoint public static final Object O3 = new Object(); | 45 @DataPoint public static final Object O3 = new Object(); |
45 @DataPoint public static final Integer O4 = new Integer(1); | 46 @DataPoint public static final Integer O4 = new Integer(1); |
46 @DataPoint public static final Integer O5 = null; | 47 @DataPoint public static final Integer O5 = null; |
48 @DataPoint public static final TestBaseClass O6 = new TestBaseClass(); | |
49 @DataPoint public static final TestSubClass O7 = new TestSubClass(); | |
47 | 50 |
48 private ValueProfile profile; | 51 private ValueProfile profile; |
52 | |
53 private static class TestBaseClass { | |
54 } | |
55 | |
56 private static class TestSubClass extends TestBaseClass { | |
57 } | |
49 | 58 |
50 @Before | 59 @Before |
51 public void create() { | 60 public void create() { |
52 profile = ValueProfile.createClassProfile(); | 61 profile = ValueProfile.createClassProfile(); |
53 } | 62 } |
55 @Test | 64 @Test |
56 public void testInitial() throws Exception { | 65 public void testInitial() throws Exception { |
57 assertThat(isGeneric(profile), is(false)); | 66 assertThat(isGeneric(profile), is(false)); |
58 assertThat(isUninitialized(profile), is(true)); | 67 assertThat(isUninitialized(profile), is(true)); |
59 assertNull(getCachedClass(profile)); | 68 assertNull(getCachedClass(profile)); |
60 profile.toString(); // test that it is not crashing | 69 assertNotNull(profile.toString()); |
61 } | 70 } |
62 | 71 |
63 @Theory | 72 @Theory |
64 public void testProfileOne(Object value) throws Exception { | 73 public void testProfileOne(Object value) throws Exception { |
65 Object result = profile.profile(value); | 74 Object result = profile.profile(value); |
66 | 75 |
67 assertThat(result, is(value)); | 76 assertThat(result, is(value)); |
68 assertEquals(getCachedClass(profile), expectedClass(value)); | 77 assertEquals(expectedClass(value), getCachedClass(profile)); |
69 assertThat(isUninitialized(profile), is(false)); | 78 assertThat(isUninitialized(profile), is(false)); |
70 profile.toString(); // test that it is not crashing | 79 assertNotNull(profile.toString()); |
71 } | 80 } |
72 | 81 |
73 @Theory | 82 @Theory |
74 public void testProfileTwo(Object value0, Object value1) throws Exception { | 83 public void testProfileTwo(Object value0, Object value1) throws Exception { |
75 Object result0 = profile.profile(value0); | 84 Object result0 = profile.profile(value0); |
78 assertThat(result0, is(value0)); | 87 assertThat(result0, is(value0)); |
79 assertThat(result1, is(value1)); | 88 assertThat(result1, is(value1)); |
80 | 89 |
81 Object expectedClass = expectedClass(value0) == expectedClass(value1) ? expectedClass(value0) : Object.class; | 90 Object expectedClass = expectedClass(value0) == expectedClass(value1) ? expectedClass(value0) : Object.class; |
82 | 91 |
83 assertEquals(getCachedClass(profile), expectedClass); | 92 assertEquals(expectedClass, getCachedClass(profile)); |
84 assertThat(isUninitialized(profile), is(false)); | 93 assertThat(isUninitialized(profile), is(false)); |
85 assertThat(isGeneric(profile), is(expectedClass == Object.class)); | 94 assertThat(isGeneric(profile), is(expectedClass == Object.class)); |
86 profile.toString(); // test that it is not crashing | 95 assertNotNull(profile.toString()); |
87 } | 96 } |
88 | 97 |
89 @Theory | 98 @Theory |
90 public void testProfileThree(Object value0, Object value1, Object value2) throws Exception { | 99 public void testProfileThree(Object value0, Object value1, Object value2) throws Exception { |
91 Object result0 = profile.profile(value0); | 100 Object result0 = profile.profile(value0); |
96 assertThat(result1, is(value1)); | 105 assertThat(result1, is(value1)); |
97 assertThat(result2, is(value2)); | 106 assertThat(result2, is(value2)); |
98 | 107 |
99 Object expectedClass = expectedClass(value0) == expectedClass(value1) && expectedClass(value1) == expectedClass(value2) ? expectedClass(value0) : Object.class; | 108 Object expectedClass = expectedClass(value0) == expectedClass(value1) && expectedClass(value1) == expectedClass(value2) ? expectedClass(value0) : Object.class; |
100 | 109 |
101 assertEquals(getCachedClass(profile), expectedClass); | 110 assertEquals(expectedClass, getCachedClass(profile)); |
102 assertThat(isUninitialized(profile), is(false)); | 111 assertThat(isUninitialized(profile), is(false)); |
103 assertThat(isGeneric(profile), is(expectedClass == Object.class)); | 112 assertThat(isGeneric(profile), is(expectedClass == Object.class)); |
104 profile.toString(); // test that it is not crashing | 113 assertNotNull(profile.toString()); |
105 } | 114 } |
106 | 115 |
107 private static Class<?> expectedClass(Object value) { | 116 private static Class<?> expectedClass(Object value) { |
108 return value == null ? Object.class : value.getClass(); | 117 return value == null ? Object.class : value.getClass(); |
109 } | 118 } |