comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IdentityValueProfileTest.java @ 17039:1e542561783e

Truffle: new value profiles prototype.
author Christian Humer <christian.humer@gmail.com>
date Wed, 03 Sep 2014 14:58:53 +0200
parents
children
comparison
equal deleted inserted replaced
17038:3b3e768a2b92 17039:1e542561783e
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.test.utilities;
24
25 import static org.hamcrest.CoreMatchers.*;
26 import static org.junit.Assert.*;
27
28 import org.junit.*;
29 import org.junit.experimental.theories.*;
30 import org.junit.runner.*;
31
32 import com.oracle.truffle.api.utilities.*;
33
34 @RunWith(Theories.class)
35 public class IdentityValueProfileTest {
36
37 @DataPoint public static final String O1 = new String();
38 @DataPoint public static final String O2 = O1;
39 @DataPoint public static final Object O3 = new Object();
40 @DataPoint public static final Integer O4 = new Integer(1);
41 @DataPoint public static final Integer O5 = null;
42
43 private IdentityValueProfile profile;
44
45 @Before
46 public void create() {
47 profile = (IdentityValueProfile) ValueProfile.createIdentityProfile();
48 }
49
50 @Test
51 public void testInitial() {
52 assertThat(profile.isGeneric(), is(false));
53 assertThat(profile.isUninitialized(), is(true));
54 profile.toString(); // test that it is not crashing
55 }
56
57 @Theory
58 public void testProfileOne(Object value) {
59 Object result = profile.profile(value);
60
61 assertThat(result, is(value));
62 assertEquals(profile.getCachedValue(), value);
63 assertThat(profile.isUninitialized(), is(false));
64 profile.toString(); // test that it is not crashing
65 }
66
67 @Theory
68 public void testProfileTwo(Object value0, Object value1) {
69 Object result0 = profile.profile(value0);
70 Object result1 = profile.profile(value1);
71
72 assertThat(result0, is(value0));
73 assertThat(result1, is(value1));
74
75 if (value0 == value1) {
76 assertThat(profile.getCachedValue(), is(value0));
77 assertThat(profile.isGeneric(), is(false));
78 } else {
79 assertThat(profile.isGeneric(), is(true));
80 }
81 assertThat(profile.isUninitialized(), is(false));
82 profile.toString(); // test that it is not crashing
83 }
84
85 @Theory
86 public void testProfileThree(Object value0, Object value1, Object value2) {
87 Object result0 = profile.profile(value0);
88 Object result1 = profile.profile(value1);
89 Object result2 = profile.profile(value2);
90
91 assertThat(result0, is(value0));
92 assertThat(result1, is(value1));
93 assertThat(result2, is(value2));
94
95 if (value0 == value1 && value1 == value2) {
96 assertThat(profile.getCachedValue(), is(value0));
97 assertThat(profile.isGeneric(), is(false));
98 } else {
99 assertThat(profile.isGeneric(), is(true));
100 }
101 assertThat(profile.isUninitialized(), is(false));
102 profile.toString(); // test that it is not crashing
103 }
104 }