From ef124776702475151a9315d86bb38d8f6bb7b0da Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 13 Mar 2009 18:36:11 -0600 Subject: [PATCH] more work on Integers.java --- test/Integers.java | 100 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/test/Integers.java b/test/Integers.java index f3b5f4a83c..80e1a0e3a5 100644 --- a/test/Integers.java +++ b/test/Integers.java @@ -65,6 +65,33 @@ public class Integers { expect(~a == ~5); } + { int a = -5; + expect(a >> 2 == -5 >> 2); + expect(a >>> 2 == -5 >>> 2); + expect(a << 2 == -5 << 2); + expect(a + 2 == -5 + 2); + expect(a - 2 == -5 - 2); + expect(a * 2 == -5 * 2); + expect(a / 2 == -5 / 2); + expect(a % 2 == -5 % 2); + expect((a & 2) == (-5 & 2)); + expect((a | 2) == (-5 | 2)); + expect((a ^ 2) == (-5 ^ 2)); + + a = 5; + expect(a >> 2 == 5 >> 2); + expect(a >>> 2 == 5 >>> 2); + expect(a << 2 == 5 << 2); + expect(a + 2 == 5 + 2); + expect(a - 2 == 5 - 2); + expect(a * 2 == 5 * 2); + expect(a / 2 == 5 / 2); + expect(a % 2 == 5 % 2); + expect((a & 2) == (5 & 2)); + expect((a | 2) == (5 | 2)); + expect((a ^ 2) == (5 ^ 2)); + } + { int a = -5; int b = 1234567; expect(a + b == -5 + 1234567); @@ -88,7 +115,28 @@ public class Integers { expect((a ^ b) == (5 ^ 1234567)); } - { int a = -1223457; + { int a = -5; + expect(a + 1234567 == -5 + 1234567); + expect(a - 1234567 == -5 - 1234567); + expect(a * 1234567 == -5 * 1234567); + expect(a / 1234567 == -5 / 1234567); + expect(a % 1234567 == -5 % 1234567); + expect((a & 1234567) == (-5 & 1234567)); + expect((a | 1234567) == (-5 | 1234567)); + expect((a ^ 1234567) == (-5 ^ 1234567)); + + a = 5; + expect(a + 1234567 == 5 + 1234567); + expect(a - 1234567 == 5 - 1234567); + expect(a * 1234567 == 5 * 1234567); + expect(a / 1234567 == 5 / 1234567); + expect(a % 1234567 == 5 % 1234567); + expect((a & 1234567) == (5 & 1234567)); + expect((a | 1234567) == (5 | 1234567)); + expect((a ^ 1234567) == (5 ^ 1234567)); + } + + { int a = -1234567; int b = 2; expect(a >> b == -1234567 >> 2); expect(a >>> b == -1234567 >>> 2); @@ -121,7 +169,34 @@ public class Integers { expect(~a == ~1234567); } - { int a = -1223457; + { int a = -1234567; + expect(a >> 2 == -1234567 >> 2); + expect(a >>> 2 == -1234567 >>> 2); + expect(a << 2 == -1234567 << 2); + expect(a + 2 == -1234567 + 2); + expect(a - 2 == -1234567 - 2); + expect(a * 2 == -1234567 * 2); + expect(a / 2 == -1234567 / 2); + expect(a % 2 == -1234567 % 2); + expect((a & 2) == (-1234567 & 2)); + expect((a | 2) == (-1234567 | 2)); + expect((a ^ 2) == (-1234567 ^ 2)); + + a = 1234567; + expect(a >> 2 == 1234567 >> 2); + expect(a >>> 2 == 1234567 >>> 2); + expect(a << 2 == 1234567 << 2); + expect(a + 2 == 1234567 + 2); + expect(a - 2 == 1234567 - 2); + expect(a * 2 == 1234567 * 2); + expect(a / 2 == 1234567 / 2); + expect(a % 2 == 1234567 % 2); + expect((a & 2) == (1234567 & 2)); + expect((a | 2) == (1234567 | 2)); + expect((a ^ 2) == (1234567 ^ 2)); + } + + { int a = -1234567; int b = 1234567; expect(a + b == -1234567 + 1234567); expect(a - b == -1234567 - 1234567); @@ -144,6 +219,27 @@ public class Integers { expect((a ^ b) == (1234567 ^ 1234567)); } + { int a = -1234567; + expect(a + 1234567 == -1234567 + 1234567); + expect(a - 1234567 == -1234567 - 1234567); + expect(a * 1234567 == -1234567 * 1234567); + expect(a / 1234567 == -1234567 / 1234567); + expect(a % 1234567 == -1234567 % 1234567); + expect((a & 1234567) == (-1234567 & 1234567)); + expect((a | 1234567) == (-1234567 | 1234567)); + expect((a ^ 1234567) == (-1234567 ^ 1234567)); + + a = 1234567; + expect(a + 1234567 == 1234567 + 1234567); + expect(a - 1234567 == 1234567 - 1234567); + expect(a * 1234567 == 1234567 * 1234567); + expect(a / 1234567 == 1234567 / 1234567); + expect(a % 1234567 == 1234567 % 1234567); + expect((a & 1234567) == (1234567 & 1234567)); + expect((a | 1234567) == (1234567 | 1234567)); + expect((a ^ 1234567) == (1234567 ^ 1234567)); + } + { int get_buffer = 2144642881; int bits_left = 30; int l = 9;