| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Dart test program for testing native float arrays. | 5 // Dart test program for testing native float arrays. |
| 6 | 6 |
| 7 // Library tag to be able to run in html test framework. | 7 // Library tag to be able to run in html test framework. |
| 8 library FloatArrayTest; | 8 library FloatArrayTest; |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 floatArray[0] = 20.0; | 35 floatArray[0] = 20.0; |
| 36 floatArray[1] = 21.0; | 36 floatArray[1] = 21.0; |
| 37 floatArray[2] = 22.0; | 37 floatArray[2] = 22.0; |
| 38 list.setRange(0, 3, floatArray); | 38 list.setRange(0, 3, floatArray); |
| 39 for (int i = 0; i < 3; i++) { | 39 for (int i = 0; i < 3; i++) { |
| 40 Expect.equals(20 + i, list[i]); | 40 Expect.equals(20 + i, list[i]); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // 4.0e40 is larger than the largest representable float. | 43 // 4.0e40 is larger than the largest representable float. |
| 44 floatArray.setRange(1, 2, const [8.0, 4.0e40]); | 44 floatArray.setRange(1, 3, const [8.0, 4.0e40]); |
| 45 Expect.equals(20, floatArray[0]); | 45 Expect.equals(20, floatArray[0]); |
| 46 Expect.equals(8, floatArray[1]); | 46 Expect.equals(8, floatArray[1]); |
| 47 Expect.equals(double.INFINITY, floatArray[2]); | 47 Expect.equals(double.INFINITY, floatArray[2]); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void testIndexOutOfRange32() { | 50 void testIndexOutOfRange32() { |
| 51 Float32List floatArray = new Float32List(3); | 51 Float32List floatArray = new Float32List(3); |
| 52 List<num> list = const [0.0, 1.0, 2.0, 3.0]; | 52 List<num> list = const [0.0, 1.0, 2.0, 3.0]; |
| 53 | 53 |
| 54 Expect.throws(() { | 54 Expect.throws(() { |
| 55 floatArray[5] = 2.0; | 55 floatArray[5] = 2.0; |
| 56 }); | 56 }); |
| 57 Expect.throws(() { | 57 Expect.throws(() { |
| 58 floatArray.setRange(0, 4, list); | 58 floatArray.setRange(0, 4, list); |
| 59 }); | 59 }); |
| 60 | 60 |
| 61 Expect.throws(() { | 61 Expect.throws(() { |
| 62 floatArray.setRange(3, 1, list); | 62 floatArray.setRange(3, 4, list); |
| 63 }); | 63 }); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void testIndexOf32() { | 66 void testIndexOf32() { |
| 67 var list = new Float32List(10); | 67 var list = new Float32List(10); |
| 68 for (int i = 0; i < list.length; i++) { | 68 for (int i = 0; i < list.length; i++) { |
| 69 list[i] = i + 10.0; | 69 list[i] = i + 10.0; |
| 70 } | 70 } |
| 71 Expect.equals(0, list.indexOf(10)); | 71 Expect.equals(0, list.indexOf(10)); |
| 72 Expect.equals(5, list.indexOf(15)); | 72 Expect.equals(5, list.indexOf(15)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 floatArray[0] = 20.0; | 119 floatArray[0] = 20.0; |
| 120 floatArray[1] = 21.0; | 120 floatArray[1] = 21.0; |
| 121 floatArray[2] = 22.0; | 121 floatArray[2] = 22.0; |
| 122 list.setRange(0, 3, floatArray); | 122 list.setRange(0, 3, floatArray); |
| 123 for (int i = 0; i < 3; i++) { | 123 for (int i = 0; i < 3; i++) { |
| 124 Expect.equals(20 + i, list[i]); | 124 Expect.equals(20 + i, list[i]); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Unlike Float32Array we can properly represent 4.0e40 | 127 // Unlike Float32Array we can properly represent 4.0e40 |
| 128 floatArray.setRange(1, 2, const [8.0, 4.0e40]); | 128 floatArray.setRange(1, 3, const [8.0, 4.0e40]); |
| 129 Expect.equals(20, floatArray[0]); | 129 Expect.equals(20, floatArray[0]); |
| 130 Expect.equals(8, floatArray[1]); | 130 Expect.equals(8, floatArray[1]); |
| 131 Expect.equals(4.0e40, floatArray[2]); | 131 Expect.equals(4.0e40, floatArray[2]); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void testIndexOutOfRange64() { | 134 void testIndexOutOfRange64() { |
| 135 Float64List floatArray = new Float64List(3); | 135 Float64List floatArray = new Float64List(3); |
| 136 List<num> list = const [0.0, 1.0, 2.0, 3.0]; | 136 List<num> list = const [0.0, 1.0, 2.0, 3.0]; |
| 137 | 137 |
| 138 Expect.throws(() { | 138 Expect.throws(() { |
| 139 floatArray[5] = 2.0; | 139 floatArray[5] = 2.0; |
| 140 }); | 140 }); |
| 141 Expect.throws(() { | 141 Expect.throws(() { |
| 142 floatArray.setRange(0, 4, list); | 142 floatArray.setRange(0, 4, list); |
| 143 }); | 143 }); |
| 144 | 144 |
| 145 Expect.throws(() { | 145 Expect.throws(() { |
| 146 floatArray.setRange(3, 1, list); | 146 floatArray.setRange(3, 4, list); |
| 147 }); | 147 }); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void testIndexOf64() { | 150 void testIndexOf64() { |
| 151 var list = new Float64List(10); | 151 var list = new Float64List(10); |
| 152 for (int i = 0; i < list.length; i++) { | 152 for (int i = 0; i < list.length; i++) { |
| 153 list[i] = i + 10.0; | 153 list[i] = i + 10.0; |
| 154 } | 154 } |
| 155 Expect.equals(0, list.indexOf(10)); | 155 Expect.equals(0, list.indexOf(10)); |
| 156 Expect.equals(5, list.indexOf(15)); | 156 Expect.equals(5, list.indexOf(15)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 testBadValues32(); | 207 testBadValues32(); |
| 208 testBadValues64(); | 208 testBadValues64(); |
| 209 // Check optimized (inlined) version of []= | 209 // Check optimized (inlined) version of []= |
| 210 Expect.throws(() { | 210 Expect.throws(() { |
| 211 storeIt32(a32, 1, 2); | 211 storeIt32(a32, 1, 2); |
| 212 }); | 212 }); |
| 213 Expect.throws(() { | 213 Expect.throws(() { |
| 214 storeIt64(a64, 1, 2); | 214 storeIt64(a64, 1, 2); |
| 215 }); | 215 }); |
| 216 } | 216 } |
| OLD | NEW |