From f3ac1dde5efa1b17e237f074501d1b9d8e4251a8 Mon Sep 17 00:00:00 2001 From: Wanqiang Ji Date: Thu, 6 Aug 2020 08:35:15 +0800 Subject: [PATCH] MAPREDUCE-7288. Fix TestLongLong#testRightShift (#2183) (cherry picked from commit dc5470ae86b96d6f84abd7354c3c056d3627871b) --- .../hadoop/examples/pi/math/TestLongLong.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java index d6f284e50f7..232c53f4d47 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/test/java/org/apache/hadoop/examples/pi/math/TestLongLong.java @@ -53,32 +53,28 @@ public class TestLongLong { verifyMultiplication(max, max); } - static void verifyRightShift(long a, long b) { - final LongLong ll = new LongLong().set(a, b); - final BigInteger bi = ll.toBigInteger(); - - for (int i = 0; i < LongLong.SIZE >> 1; i++) { - final long result = ll.shiftRight(i) & MASK; - final long expected = bi.shiftRight(i).longValue() & MASK; - final String s = String.format( - "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, - b); - Assert.assertEquals(s, expected, result); - } - - final String s = String.format( - "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, - b); - //System.out.println(s); - Assert.assertEquals(s, bi, ll.toBigInteger()); - } - @Test public void testRightShift() { for(int i = 0; i < 1000; i++) { final long a = nextPositiveLong(); final long b = nextPositiveLong(); - verifyMultiplication(a, b); + verifyRightShift(a, b); + } + } + + private static void verifyRightShift(long a, long b) { + final LongLong ll = new LongLong().set(a, b); + final BigInteger bi = ll.toBigInteger(); + + final String s = String.format( + "\na = %x\nb = %x\nll= " + ll + "\nbi= " + bi.toString(16) + "\n", a, + b); + Assert.assertEquals(s, bi, ll.toBigInteger()); + + for (int i = 0; i < LongLong.SIZE >> 1; i++) { + final long result = ll.shiftRight(i) & MASK; + final long expected = bi.shiftRight(i).longValue() & MASK; + Assert.assertEquals(s, expected, result); } } }