comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/utilities/CountingConditionProfileTest.java @ 22424:fec62e298245

Rename package truffle.api.test to truffle.api to enable package-protected API access for testing.
author Christian Humer <christian.humer@oracle.com>
date Wed, 02 Dec 2015 15:16:27 +0100
parents truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/CountingConditionProfileTest.java@dc83cc1f94f2
children b39b603e2a1e
comparison
equal deleted inserted replaced
22423:70a10a9f28ad 22424:fec62e298245
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.utilities;
24
25 import com.oracle.truffle.api.utilities.ConditionProfile;
26 import com.oracle.truffle.api.utilities.CountingConditionProfile;
27 import static org.hamcrest.CoreMatchers.is;
28 import static org.junit.Assert.assertThat;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.experimental.theories.DataPoints;
32 import org.junit.experimental.theories.Theories;
33 import org.junit.experimental.theories.Theory;
34 import org.junit.runner.RunWith;
35
36 @RunWith(Theories.class)
37 public class CountingConditionProfileTest {
38
39 @DataPoints public static boolean[] data = new boolean[]{true, false};
40
41 private CountingConditionProfile profile;
42
43 @Before
44 public void create() {
45 profile = (CountingConditionProfile) ConditionProfile.createCountingProfile();
46 }
47
48 @Test
49 public void testInitial() {
50 assertThat(profile.getTrueCount(), is(0));
51 assertThat(profile.getFalseCount(), is(0));
52 }
53
54 @Theory
55 public void testProfileOne(boolean value) {
56 boolean result = profile.profile(value);
57
58 assertThat(result, is(value));
59 assertThat(profile.getTrueCount(), is(value ? 1 : 0));
60 assertThat(profile.getFalseCount(), is(!value ? 1 : 0));
61 }
62
63 @Theory
64 public void testProfileTwo(boolean value0, boolean value1) {
65 boolean result0 = profile.profile(value0);
66 boolean result1 = profile.profile(value1);
67
68 assertThat(result0, is(value0));
69 assertThat(result1, is(value1));
70 assertThat(profile.getTrueCount(), is((value0 ? 1 : 0) + (value1 ? 1 : 0)));
71 assertThat(profile.getFalseCount(), is((!value0 ? 1 : 0) + (!value1 ? 1 : 0)));
72 }
73
74 @Theory
75 public void testProfileThree(boolean value0, boolean value1, boolean value2) {
76 boolean result0 = profile.profile(value0);
77 boolean result1 = profile.profile(value1);
78 boolean result2 = profile.profile(value2);
79
80 assertThat(result0, is(value0));
81 assertThat(result1, is(value1));
82 assertThat(result2, is(value2));
83 assertThat(profile.getTrueCount(), is((value0 ? 1 : 0) + (value1 ? 1 : 0) + (value2 ? 1 : 0)));
84 assertThat(profile.getFalseCount(), is((!value0 ? 1 : 0) + (!value1 ? 1 : 0) + (!value2 ? 1 : 0)));
85 }
86
87 }