diff options
author | jeffhao <jeffhao@google.com> | 2011-09-29 17:41:15 -0700 |
---|---|---|
committer | jeffhao <jeffhao@google.com> | 2011-09-29 17:41:15 -0700 |
commit | 5d1ac920fdaef5d4ec8f66bb734488cd9660b024 (patch) | |
tree | dd372f306ab70f4c86759869b1f74eca62ff6f2b /test/027-arithmetic | |
parent | c31664f3d82e6cd68275a529a8a73f067a52e8be (diff) | |
download | art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.gz art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.tar.bz2 art-5d1ac920fdaef5d4ec8f66bb734488cd9660b024.zip |
Adding old unit tests to test suite.
These tests are copied straight over. They'll still run, but they're
using the old system.
Change-Id: If494519e52ddf858a9febfc55bdae830468cb3c8
Diffstat (limited to 'test/027-arithmetic')
-rw-r--r-- | test/027-arithmetic/expected.txt | 18 | ||||
-rw-r--r-- | test/027-arithmetic/info.txt | 6 | ||||
-rw-r--r-- | test/027-arithmetic/src/Main.java | 141 |
3 files changed, 165 insertions, 0 deletions
diff --git a/test/027-arithmetic/expected.txt b/test/027-arithmetic/expected.txt new file mode 100644 index 0000000000..2dadf10d96 --- /dev/null +++ b/test/027-arithmetic/expected.txt @@ -0,0 +1,18 @@ +f=1234.5677 --> i=1234 +f=-1234.5677 --> i=-1234 +d=1234.5678 --> i=1234 +d=-1234.5678 --> i=-1234 +d=5.6789567890123E9 --> l=5678956789 +d=-5.6789567890123E9 --> l=-5678956789 +i=7654 --> l=7654 +i=-7654 --> l=-7654 +l=5678956789 --> i=1383989493 +l=-5678956789 --> i=-1383989493 +i=1234 --> f=1234.0 +i=-1234 --> f=-1234.0 +values are 44332211 and bbaa9988 +First l is bbaa998844332211 +Second l is bbaa998844332211 +shiftTest2 l is 1122334455667788 +b=-1, s=-1, c=4095, i=268435455 +b=0xffffffff, s=0xffffffff, c=0xfff, i=0xfffffff diff --git a/test/027-arithmetic/info.txt b/test/027-arithmetic/info.txt new file mode 100644 index 0000000000..08127da231 --- /dev/null +++ b/test/027-arithmetic/info.txt @@ -0,0 +1,6 @@ +This is a miscellaneous test that was imported into the new-at-the-time +runtime test framework. The test is intended to exercise basic features, +and as such cannot be build on top of junit, since failure of such basic +features might disrupt junit. + +TODO: Real description goes here. diff --git a/test/027-arithmetic/src/Main.java b/test/027-arithmetic/src/Main.java new file mode 100644 index 0000000000..4d0f74e7d1 --- /dev/null +++ b/test/027-arithmetic/src/Main.java @@ -0,0 +1,141 @@ +// Copyright 2006 The Android Open Source Project + +/** + * Test arithmetic operations. + */ +public class Main { + + static void shiftTest1() + { + final int[] mBytes = { + 0x11, 0x22, 0x33, 0x44, 0x88, 0x99, 0xaa, 0xbb + }; + long l; + int i1, i2; + + i1 = mBytes[0] | mBytes[1] << 8 | mBytes[2] << 16 | mBytes[3] << 24; + i2 = mBytes[4] | mBytes[5] << 8 | mBytes[6] << 16 | mBytes[7] << 24; + l = i1 | ((long)i2 << 32); + + System.out.println("values are " + Integer.toHexString(i1) + + " and " + Integer.toHexString(i2)); + + System.out.println("First l is " + Long.toHexString(l)); + + l = (long)mBytes[0] + | (long)mBytes[1] << 8 + | (long)mBytes[2] << 16 + | (long)mBytes[3] << 24 + | (long)mBytes[4] << 32 + | (long)mBytes[5] << 40 + | (long)mBytes[6] << 48 + | (long)mBytes[7] << 56; + + System.out.println("Second l is " + Long.toHexString(l)); + } + + static void shiftTest2() + { + long a = 0x11; + long b = 0x22; + long c = 0x33; + long d = 0x44; + long e = 0x55; + long f = 0x66; + long g = 0x77; + long h = 0x88; + + long result = ((a << 56) | (b << 48) | (c << 40) | (d << 32) | + (e << 24) | (f << 16) | (g << 8) | h); + + System.out.println("shiftTest2 l is " + Long.toHexString(result)); + } + + static void convTest() + { + float f; + double d; + int i; + long l; + + /* float --> int */ + f = 1234.5678f; + i = (int) f; + System.out.println("f=" + f + " --> i=" + i); + + f = -1234.5678f; + i = (int) f; + System.out.println("f=" + f + " --> i=" + i); + + /* double --> int */ + d = 1234.5678; + i = (int) d; + System.out.println("d=" + d + " --> i=" + i); + + d = -1234.5678; + i = (int) d; + System.out.println("d=" + d + " --> i=" + i); + + /* double --> long */ + d = 5678956789.0123; + l = (long) d; + System.out.println("d=" + d + " --> l=" + l); + + d = -5678956789.0123; + l = (long) d; + System.out.println("d=" + d + " --> l=" + l); + + /* int --> long */ + i = 7654; + l = (long) i; + System.out.println("i=" + i + " --> l=" + l); + + i = -7654; + l = (long) i; + System.out.println("i=" + i + " --> l=" + l); + + /* long --> int (with truncation) */ + l = 5678956789L; + i = (int) l; + System.out.println("l=" + l + " --> i=" + i); + + l = -5678956789L; + i = (int) l; + System.out.println("l=" + l + " --> i=" + i); + + /* int --> float */ + i = 1234; + f = (float) i; + System.out.println("i=" + i + " --> f=" + f); + + i = -1234; + f = (float) i; + System.out.println("i=" + i + " --> f=" + f); + } + + static void unsignedShiftTest() + { + byte b = -4; + short s = -4; + char c = 0xfffc; + int i = -4; + + b >>>= 4; + s >>>= 4; + c >>>= 4; + i >>>= 4; + + System.out.println("b=" + b + ", s=" + s + ", c=" + (int)c + ", i=" +i); + System.out.println("b=0x" + Integer.toHexString((int)b) + + ", s=0x" + Integer.toHexString((int)s) + + ", c=0x" + Integer.toHexString((int)c) + + ", i=0x" + Integer.toHexString(i)); + } + + public static void main(String[] args) { + convTest(); + shiftTest1(); + shiftTest2(); + unsignedShiftTest(); + } +} |