Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #import('../../../fixnum/fixnum.dart'); | |
| 6 | |
| 7 class Int32Test { | |
|
Mads Ager (google)
2012/05/15 07:37:39
No need for the class.
Tests are no longer in a s
| |
| 8 | |
| 9 static void testMain() { | |
| 10 Expect.equals("0", new int32.fromInt(0).toString()); | |
| 11 Expect.equals("1", new int32.fromInt(1).toString()); | |
| 12 Expect.equals("-1", new int32.fromInt(-1).toString()); | |
| 13 Expect.equals("1000", new int32.fromInt(1000).toString()); | |
| 14 Expect.equals("-1000", new int32.fromInt(-1000).toString()); | |
| 15 Expect.equals("2147483647", new int32.fromInt(2147483647).toString()); | |
| 16 Expect.equals("-2147483648", new int32.fromInt(2147483648).toString()); | |
| 17 Expect.equals("-2147483647", new int32.fromInt(2147483649).toString()); | |
| 18 Expect.equals("-2147483646", new int32.fromInt(2147483650).toString()); | |
| 19 Expect.equals("-2147483648", new int32.fromInt(-2147483648).toString()); | |
| 20 Expect.equals("2147483647", new int32.fromInt(-2147483649).toString()); | |
| 21 Expect.equals("2147483646", new int32.fromInt(-2147483650).toString()); | |
| 22 | |
| 23 Expect.equals("-1", new int32.fromInt(-1).toHexString()); | |
| 24 Expect.equals("-1", (new int32.fromInt(-1) >> 8).toHexString()); | |
| 25 Expect.equals("-100", (new int32.fromInt(-1) << 8).toHexString()); | |
| 26 Expect.equals("FFFFFF", | |
| 27 new int32.fromInt(-1).shiftRightUnsigned(8).toHexString()); | |
| 28 | |
| 29 Expect.equals("123456789", new int32.fromInt(123456789).toString()); | |
| 30 Expect.equals("75BCD15", new int32.fromInt(123456789).toHexString()); | |
| 31 Expect.equals("223101104124", new int32.fromInt(123456789).toRadixString(5)) ; | |
|
Mads Ager (google)
2012/05/15 07:37:39
Long lines.
| |
| 32 | |
| 33 try { | |
| 34 new int32.fromInt(17) >> -1; | |
| 35 Expect.fail("x >> -1 should throw IllegalArgumentException"); | |
| 36 } catch (IllegalArgumentException e) { | |
| 37 } | |
| 38 | |
| 39 try { | |
| 40 new int32.fromInt(17) << -1; | |
| 41 Expect.fail("x >> -1 should throw IllegalArgumentException"); | |
| 42 } catch (IllegalArgumentException e) { | |
| 43 } | |
| 44 | |
| 45 try { | |
| 46 new int32.fromInt(17).shiftRightUnsigned(-1); | |
| 47 Expect.fail("x >> -1 should throw IllegalArgumentException"); | |
| 48 } catch (IllegalArgumentException e) { | |
| 49 } | |
| 50 | |
| 51 // wraparound | |
| 52 Expect.equals("-67153019", | |
| 53 (new int32.fromInt(123456789) * new int32.fromInt(987654321)).toString() ); | |
| 54 Expect.equals("121932631112635269", | |
| 55 (new int64.fromInt(123456789) * new int32.fromInt(987654321)).toString() ); | |
| 56 Expect.equals("121932631112635269", | |
| 57 (new int32.fromInt(123456789) * new int64.fromInt(987654321)).toString() ); | |
| 58 Expect.equals("121932631112635269", | |
| 59 (new int64.fromInt(123456789) * new int64.fromInt(987654321)).toString() ); | |
| 60 | |
| 61 Expect.equals("432461", | |
| 62 (new int32.fromInt(829893893) ~/ new int32.fromInt(1919)).toString()); | |
| 63 Expect.equals("432461", | |
| 64 (new int32.fromInt(829893893) ~/ new int64.fromInt(1919)).toString()); | |
| 65 Expect.equals("432461", | |
| 66 (new int64.fromInt(829893893) ~/ new int32.fromInt(1919)).toString()); | |
| 67 Expect.equals("432461", | |
| 68 (new int64.fromInt(829893893) ~/ new int64.fromInt(1919)).toString()); | |
| 69 Expect.equals("432461", | |
| 70 (new int32.fromInt(829893893) ~/ 1919).toString()); | |
| 71 Expect.equals("432461", | |
| 72 (new int64.fromInt(829893893) ~/ 1919).toString()); | |
| 73 | |
| 74 Expect.isTrue(new int32.fromInt(12345) == 12345); | |
| 75 Expect.isTrue(new int32.fromInt(12345) == new int32.fromInt(12345)); | |
| 76 Expect.isTrue(new int64.fromInt(12345) == new int32.fromInt(12345)); | |
| 77 | |
| 78 Expect.equals(new int32.fromInt(~0x12345678), | |
| 79 ~(new int32.fromInt(0x12345678))); | |
| 80 Expect.equals(new int64.fromInt(-0x12345678), | |
| 81 -(new int32.fromInt(0x12345678))); | |
| 82 | |
| 83 Expect.equals(new int32.fromInt(0x12345678 & 0x22222222), | |
| 84 new int32.fromInt(0x12345678) & new int32.fromInt(0x22222222)); | |
| 85 Expect.equals(new int64.fromInt(0x12345678 & 0x22222222), | |
| 86 new int32.fromInt(0x12345678) & new int64.fromInt(0x22222222)); | |
| 87 Expect.equals(new int32.fromInt(0x12345678 | 0x22222222), | |
| 88 new int32.fromInt(0x12345678) | new int32.fromInt(0x22222222)); | |
| 89 Expect.equals(new int64.fromInt(0x12345678 | 0x22222222), | |
| 90 new int32.fromInt(0x12345678) | new int64.fromInt(0x22222222)); | |
| 91 Expect.equals(new int32.fromInt(0x12345678 ^ 0x22222222), | |
| 92 new int32.fromInt(0x12345678) ^ new int32.fromInt(0x22222222)); | |
| 93 Expect.equals(new int64.fromInt(0x12345678 ^ 0x22222222), | |
| 94 new int32.fromInt(0x12345678) ^ new int64.fromInt(0x22222222)); | |
| 95 | |
| 96 Expect.equals(new int32.fromInt(0x12345678 + 0x22222222), | |
| 97 new int32.fromInt(0x12345678) + new int32.fromInt(0x22222222)); | |
| 98 Expect.equals(new int64.fromInt(0x12345678 + 0x22222222), | |
| 99 new int32.fromInt(0x12345678) + new int64.fromInt(0x22222222)); | |
| 100 Expect.equals(new int32.fromInt(0x12345678 - 0x22222222), | |
| 101 new int32.fromInt(0x12345678) - new int32.fromInt(0x22222222)); | |
| 102 Expect.equals(new int64.fromInt(0x12345678 - 0x22222222), | |
| 103 new int32.fromInt(0x12345678) - new int64.fromInt(0x22222222)); | |
| 104 Expect.equals(new int32.fromInt(-899716112), | |
| 105 new int32.fromInt(0x12345678) * new int32.fromInt(0x22222222)); | |
| 106 Expect.equals(new int64.fromInts(0x026D60DC, 0xCA5F6BF0), | |
| 107 new int32.fromInt(0x12345678) * new int64.fromInt(0x22222222)); | |
| 108 Expect.equals(new int32.fromInt(0x12345678 % 0x22), | |
| 109 new int32.fromInt(0x12345678) % new int32.fromInt(0x22)); | |
| 110 Expect.equals(new int32.fromInt(0x12345678 % 0x22), | |
| 111 new int32.fromInt(0x12345678) % new int64.fromInt(0x22)); | |
| 112 Expect.equals(new int32.fromInt(0x12345678.remainder(0x22)), | |
| 113 new int32.fromInt(0x12345678).remainder(new int32.fromInt(0x22))); | |
| 114 Expect.equals(new int32.fromInt(0x12345678.remainder(-0x22)), | |
| 115 new int32.fromInt(0x12345678).remainder(new int32.fromInt(-0x22))); | |
| 116 Expect.equals(new int32.fromInt(-0x12345678.remainder(-0x22)), | |
| 117 new int32.fromInt(-0x12345678).remainder(new int32.fromInt(-0x22))); | |
| 118 Expect.equals(new int32.fromInt(-0x12345678.remainder(0x22)), | |
| 119 new int32.fromInt(-0x12345678).remainder(new int32.fromInt(0x22))); | |
| 120 Expect.equals(new int32.fromInt(0x12345678.remainder(0x22)), | |
| 121 new int32.fromInt(0x12345678).remainder(new int64.fromInt(0x22))); | |
| 122 Expect.equals(new int32.fromInt(0x12345678 ~/ 0x22), | |
| 123 new int32.fromInt(0x12345678) ~/ new int32.fromInt(0x22)); | |
| 124 Expect.equals(new int32.fromInt(0x12345678 ~/ 0x22), | |
| 125 new int32.fromInt(0x12345678) ~/ new int64.fromInt(0x22)); | |
| 126 | |
| 127 Expect.equals(new int32.fromInt(0x12345678 >> 7), | |
| 128 new int32.fromInt(0x12345678) >> 7); | |
| 129 Expect.equals(new int32.fromInt(0x12345678 << 7), | |
| 130 new int32.fromInt(0x12345678) << 7); | |
| 131 Expect.equals(new int32.fromInt(0x12345678 >> 7), | |
| 132 new int32.fromInt(0x12345678).shiftRightUnsigned(7)); | |
| 133 | |
| 134 try { | |
| 135 new int32.fromInt(17) < null; | |
| 136 Expect.fail("x < null should throw NullPointerException"); | |
| 137 } catch (NullPointerException e) { | |
| 138 } | |
| 139 | |
| 140 try { | |
| 141 new int32.fromInt(17) <= null; | |
| 142 Expect.fail("x <= null should throw NullPointerException"); | |
| 143 } catch (NullPointerException e) { | |
| 144 } | |
| 145 | |
| 146 try { | |
| 147 new int32.fromInt(17) > null; | |
| 148 Expect.fail("x > null should throw NullPointerException"); | |
| 149 } catch (NullPointerException e) { | |
| 150 } | |
| 151 | |
| 152 try { | |
| 153 new int32.fromInt(17) < null; | |
| 154 Expect.fail("x >= null should throw NullPointerException"); | |
| 155 } catch (NullPointerException e) { | |
| 156 } | |
| 157 | |
| 158 Expect.isFalse(new int32.fromInt(17) == null); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 main() { | |
| 163 Int32Test.testMain(); | |
| 164 } | |
| OLD | NEW |