| 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 byte 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("ByteArrayTest.dart"); | 8 #library("FloatArrayTest.dart"); |
| 9 | 9 |
| 10 #import('dart:scalarlist'); | 10 #import('dart:scalarlist'); |
| 11 | 11 |
| 12 void testCreateByteArray() { | 12 void testCreateFloatArray() { |
| 13 Uint8List byteArray; | 13 Float32List floatArray; |
| 14 | 14 |
| 15 byteArray = new Uint8List(0); | 15 floatArray = new Float32List(0); |
| 16 Expect.equals(0, byteArray.length); | 16 Expect.equals(0, floatArray.length); |
| 17 | 17 |
| 18 byteArray = new Uint8List(10); | 18 floatArray = new Float32List(10); |
| 19 Expect.equals(10, byteArray.length); | 19 Expect.equals(10, floatArray.length); |
| 20 for (int i = 0; i < 10; i++) { | 20 for (int i = 0; i < 10; i++) { |
| 21 Expect.equals(0, byteArray[i]); | 21 Expect.equals(0.0, floatArray[i]); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 void testSetRange() { | 25 void testSetRange() { |
| 26 Uint8List byteArray = new Uint8List(3); | 26 Float32List floatArray = new Float32List(3); |
| 27 | 27 |
| 28 List<int> list = [10, 11, 12]; | 28 List<num> list = [10.0, 11.0, 12.0]; |
| 29 byteArray.setRange(0, 3, list); | 29 floatArray.setRange(0, 3, list); |
| 30 for (int i = 0; i < 3; i++) { | 30 for (int i = 0; i < 3; i++) { |
| 31 Expect.equals(10 + i, byteArray[i]); | 31 Expect.equals(10 + i, floatArray[i]); |
| 32 } | 32 } |
| 33 | 33 |
| 34 byteArray[0] = 20; | 34 floatArray[0] = 20.0; |
| 35 byteArray[1] = 21; | 35 floatArray[1] = 21.0; |
| 36 byteArray[2] = 22; | 36 floatArray[2] = 22.0; |
| 37 list.setRange(0, 3, byteArray); | 37 list.setRange(0, 3, floatArray); |
| 38 for (int i = 0; i < 3; i++) { | 38 for (int i = 0; i < 3; i++) { |
| 39 Expect.equals(20 + i, list[i]); | 39 Expect.equals(20 + i, list[i]); |
| 40 } | 40 } |
| 41 | 41 |
| 42 byteArray.setRange(1, 2, const [8, 9]); | 42 floatArray.setRange(1, 2, const [8.0, 9.0]); |
| 43 Expect.equals(20, byteArray[0]); | 43 Expect.equals(20, floatArray[0]); |
| 44 Expect.equals(8, byteArray[1]); | 44 Expect.equals(8, floatArray[1]); |
| 45 Expect.equals(9, byteArray[2]); | 45 Expect.equals(9, floatArray[2]); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void testIndexOutOfRange() { | 48 void testIndexOutOfRange() { |
| 49 Uint8List byteArray = new Uint8List(3); | 49 Float32List floatArray = new Float32List(3); |
| 50 List<int> list = const [0, 1, 2, 3]; | 50 List<num> list = const [0.0, 1.0, 2.0, 3.0]; |
| 51 | 51 |
| 52 Expect.throws(() { | 52 Expect.throws(() { |
| 53 byteArray.setRange(0, 4, list); | 53 floatArray.setRange(0, 4, list); |
| 54 }); | 54 }); |
| 55 | 55 |
| 56 Expect.throws(() { | 56 Expect.throws(() { |
| 57 byteArray.setRange(3, 1, list); | 57 floatArray.setRange(3, 1, list); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void testIndexOf() { | 61 void testIndexOf() { |
| 62 var list = new Uint8List(10); | 62 var list = new Float32List(10); |
| 63 for (int i = 0; i < list.length; i++) { | 63 for (int i = 0; i < list.length; i++) { |
| 64 list[i] = i + 10; | 64 list[i] = i + 10.0; |
| 65 } | 65 } |
| 66 Expect.equals(0, list.indexOf(10)); | 66 Expect.equals(0, list.indexOf(10)); |
| 67 Expect.equals(5, list.indexOf(15)); | 67 Expect.equals(5, list.indexOf(15)); |
| 68 Expect.equals(9, list.indexOf(19)); | 68 Expect.equals(9, list.indexOf(19)); |
| 69 Expect.equals(-1, list.indexOf(20)); | 69 Expect.equals(-1, list.indexOf(20)); |
| 70 | 70 |
| 71 list = new Float32List(10); | 71 list = new Float32List(10); |
| 72 for (int i = 0; i < list.length; i++) { | 72 for (int i = 0; i < list.length; i++) { |
| 73 list[i] = i + 10.0; | 73 list[i] = i + 10.0; |
| 74 } | 74 } |
| 75 Expect.equals(0, list.indexOf(10.0)); | 75 Expect.equals(0, list.indexOf(10.0)); |
| 76 Expect.equals(5, list.indexOf(15.0)); | 76 Expect.equals(5, list.indexOf(15.0)); |
| 77 Expect.equals(9, list.indexOf(19.0)); | 77 Expect.equals(9, list.indexOf(19.0)); |
| 78 Expect.equals(-1, list.indexOf(20.0)); | 78 Expect.equals(-1, list.indexOf(20.0)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 main() { | 81 main() { |
| 82 for (int i = 0; i < 2000; i++) { | 82 for (int i = 0; i < 2000; i++) { |
| 83 testCreateByteArray(); | 83 testCreateFloatArray(); |
| 84 testSetRange(); | 84 testSetRange(); |
| 85 testIndexOutOfRange(); | 85 testIndexOutOfRange(); |
| 86 testIndexOf(); | 86 testIndexOf(); |
| 87 } | 87 } |
| 88 } | 88 } |
| OLD | NEW |