lin
2025-07-31 065ea569db06206874bbfa18eb25ff6121aec09b
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
/*
 * Copyright (C) 2018 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.
 */
 
import java.lang.reflect.Method;
 
public class Main {
  static long smallLong = 42L;
  static long smallLongShlOne = 84L;
  static long smallLongShrOne = 21L;
  static long smallLongUShrOne = 21L;
  static long longLong = 123456789123456789L;
  static long longLongShlOne = 246913578246913578L;
  static long longLongShrOne = 61728394561728394L;
  static long longLongUShrOne = 61728394561728394L;
 
  static long negativeSmallLong = -42L;
  static long negativeSmallLongShlOne = -84L;
  static long negativeSmallLongShrOne = -21L;
  static long negativeSmallLongUShrOne = 9223372036854775787L;
  static long negativeLongLong = -123456789123456789L;
  static long negativeLongLongShlOne = -246913578246913578L;
  static long negativeLongLongShrOne = -61728394561728395L;
  static long negativeLongLongUShrOne = 9161643642293047413L;
 
  private static void assertEquals(long expected, long actual) {
    if (expected != actual) {
      throw new Error("Expected " + expected + ", got " + actual);
    }
  }
 
  public static void main(String[] args) throws Exception {
    Class<?> c = Class.forName("Test");
    Method m = c.getMethod("shlZero", long.class);
    assertEquals(smallLong, (Long)m.invoke(null, smallLong));
    assertEquals(longLong, (Long)m.invoke(null, longLong));
 
    m = c.getMethod("shrZero", long.class);
    assertEquals(smallLong, (Long)m.invoke(null, smallLong));
    assertEquals(longLong, (Long)m.invoke(null, longLong));
 
    m = c.getMethod("ushrZero", long.class);
    assertEquals(smallLong, (Long)m.invoke(null, smallLong));
    assertEquals(longLong, (Long)m.invoke(null, longLong));
 
    m = c.getMethod("shlOne", long.class);
    assertEquals(smallLongShlOne, (Long)m.invoke(null, smallLong));
    assertEquals(longLongShlOne, (Long)m.invoke(null, longLong));
 
    m = c.getMethod("shrOne", long.class);
    assertEquals(smallLongShrOne, (Long)m.invoke(null, smallLong));
    assertEquals(longLongShrOne, (Long)m.invoke(null, longLong));
 
    m = c.getMethod("ushrOne", long.class);
    assertEquals(smallLongUShrOne, (Long)m.invoke(null, smallLong));
    assertEquals(longLongUShrOne, (Long)m.invoke(null, longLong));
 
    // Test with negative numbers.
 
    m = c.getMethod("shlZero", long.class);
    assertEquals(negativeSmallLong, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLong, (Long)m.invoke(null, negativeLongLong));
 
    m = c.getMethod("shrZero", long.class);
    assertEquals(negativeSmallLong, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLong, (Long)m.invoke(null, negativeLongLong));
 
    m = c.getMethod("ushrZero", long.class);
    assertEquals(negativeSmallLong, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLong, (Long)m.invoke(null, negativeLongLong));
 
    m = c.getMethod("shlOne", long.class);
    assertEquals(negativeSmallLongShlOne, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLongShlOne, (Long)m.invoke(null, negativeLongLong));
 
    m = c.getMethod("shrOne", long.class);
    assertEquals(negativeSmallLongShrOne, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLongShrOne, (Long)m.invoke(null, negativeLongLong));
 
    m = c.getMethod("ushrOne", long.class);
    assertEquals(negativeSmallLongUShrOne, (Long)m.invoke(null, negativeSmallLong));
    assertEquals(negativeLongLongUShrOne, (Long)m.invoke(null, negativeLongLong));
  }
}