summaryrefslogtreecommitdiffstats
path: root/jack-tests/tests/com/android/jack/optimizations/notsimplifier/test002/dx/Tests.java
blob: b07b4cc59d797618d9724910d5a6608e7e720a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.jack.optimizations.notsimplifier.test002.dx;

import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithComparisonOperator;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithEQ;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithGT;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithGTE;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithLT;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithLTE;
import com.android.jack.optimizations.notsimplifier.test002.jack.NotWithNEQ;

import junit.framework.Assert;

import org.junit.Test;

/**
 * Tests about '!' simplifier optimization using comparison with bounds values or not of types.
 */
public class Tests {

  @Test
  public void test() {
    NotWithComparisonOperator[] operators = new NotWithComparisonOperator[] {
        new NotWithGT(),
        new NotWithGTE(),
        new NotWithEQ(),
        new NotWithNEQ(),
        new NotWithLT(),
        new NotWithLTE()};

    double[] doubleValues = new double[] {
        Double.NaN,
        0.0d,
        -5.0d,
        -Double.MIN_VALUE,
        Double.NEGATIVE_INFINITY,
        Double.POSITIVE_INFINITY,
        Double.MAX_VALUE,
        5.0d};

    float[] floatValues = new float[] {
        Float.NaN,
        0.0f,
        -5.0f,
        -Float.MIN_VALUE,
        Float.NEGATIVE_INFINITY,
        Float.POSITIVE_INFINITY,
        Float.MAX_VALUE,
        5.0f};

    int[] intValues = new int[] {
        0,
        -5,
        -Integer.MIN_VALUE,
        Integer.MAX_VALUE,
        1};

    long[] longValues = new long[] {
        0l,
        -5l,
        -Long.MIN_VALUE,
        Long.MAX_VALUE,
        1l};

    byte[] byteValues = new byte[] {
        (byte) 0,
        (byte) -5,
        Byte.MIN_VALUE,
        Byte.MAX_VALUE,
        (byte) 1};

    short[] shortValues = new short[] {
        (short) 0,
        (short) -5,
        Short.MIN_VALUE,
        Short.MAX_VALUE,
        (short) 1};

    char[] charValues = new char[] {
        (char) 0,
        Character.MIN_VALUE,
        Character.MAX_VALUE};

    boolean[][] resultForDoubleAndFloat =
        new boolean[][] {
        {true, true, true, true, true, false, false, false}, // GT
        {true, false, true, true, true, false, false, false}, // GTE
        {true, false, true, true, true, true, true, true}, // EQ
        {false, true, false, false, false, false, false, false}, // NEQ
        {true, true, false, false, false, true, true, true}, // LT
        {true, false, false, false, false, true, true, true}, // LTE
        };

    boolean[][] resultForLongIntShortByte =
        new boolean[][] {
        {true, true, true, false, false}, // GT
        {false, true, true, false, false}, // GTE
        {false, true, true, true, true}, // EQ
        {true, false, false, false, false}, // NEQ
        {true, false, false, true, true}, // LT
        {false, false, false, true, true}, // LTE
        };

    boolean[][] resultForChar =
        new boolean[][] {
        {true, true, false}, // GT
        {false,false, false}, // GTE
        {false, false, true}, // EQ
        {true, true, false}, // NEQ
        {true, true, true}, // LT
        {false, false, true}, // LTE
        };

    for (int operatorIndex = 0; operatorIndex < operators.length; operatorIndex++) {
      NotWithComparisonOperator operator = operators[operatorIndex];

      for (int valueIndex = 0; valueIndex < doubleValues.length; valueIndex++) {
        Assert.assertEquals(resultForDoubleAndFloat[operatorIndex][valueIndex],
            operator.testWithDouble(doubleValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < floatValues.length; valueIndex++) {
        Assert.assertEquals(resultForDoubleAndFloat[operatorIndex][valueIndex],
            operator.testWithFloat(floatValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < intValues.length; valueIndex++) {
        Assert.assertEquals(resultForLongIntShortByte[operatorIndex][valueIndex],
            operator.testWithInt(intValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < longValues.length; valueIndex++) {
        Assert.assertEquals(resultForLongIntShortByte[operatorIndex][valueIndex],
            operator.testWithLong(longValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < byteValues.length; valueIndex++) {
        Assert.assertEquals(resultForLongIntShortByte[operatorIndex][valueIndex],
            operator.testWithByte(byteValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < shortValues.length; valueIndex++) {
        Assert.assertEquals(resultForLongIntShortByte[operatorIndex][valueIndex],
            operator.testWithShort(shortValues[valueIndex]));
      }

      for (int valueIndex = 0; valueIndex < charValues.length; valueIndex++) {
        Assert.assertEquals(resultForChar[operatorIndex][valueIndex],
            operator.testWithChar(charValues[valueIndex]));
      }
    }
  }
}