Skip to content

Commit

Permalink
Fixes #2355. Add more typed_date.setRange() tests (#2412)
Browse files Browse the repository at this point in the history
This PR adds many new tests. The idea is to test each `setRange()` of an `int` type against a `float` type of the same size (to ensure that we have an error, not a memcpy). Next, we test it against a type of a smaller size, and against a type of a bigger size. We do the same for each `float` against `int`.

We have float types with sizes 32, 64, and 128 (32x4 and 64x2) only. Therefore we test `Int16` against `Uint8` and `Uint16` in case of small and equal size, which is not an error. 

When we are checking 32-bit type against 16, 32 and 64 bit, the latter case is moved to separate tests because it has to be switched off on web configurations.

Issue dart-lang/sdk#53945 exists for `x` types as well, so we test them, too.
  • Loading branch information
sgrekhov authored Dec 6, 2023
1 parent 0433c49 commit af60144
Show file tree
Hide file tree
Showing 39 changed files with 1,048 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LibTest/typed_data/Float32List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test data of the same size
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
List<num> ints = Uint32List.fromList([1, 2, 3, 4]);
Float32List floats = Float32List(4);
Expect.throws(() {
// Check that it's no memcopy of the same-sized data
(floats as List<num>).setRange(0, 4, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float32List/setRange_A06_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
List<num> ints = Uint16List.fromList([1, 2, 3, 4]);
Float32List floats = Float32List(4);
Expect.throws(() {
(floats as List<num>).setRange(0, 4, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float32List/setRange_A06_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test larger-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
List<num> ints = Uint64List.fromList([1, 2, 3, 4]);
Float32List floats = Float32List(4);
Expect.throws(() {
(floats as List<num>).setRange(0, 4, ints);
});
}
27 changes: 27 additions & 0 deletions LibTest/typed_data/Float32x4List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test list elements of the same size
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int32x4List.fromList([Int32x4(1, 1, 1, 1), Int32x4(2, 2, 2, 2)]);
Float32x4List floats = Float32x4List(2);
Expect.throws(() {
// Check that it's no memcopy of the same-sized data
(floats as dynamic).setRange(0, 2, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float32x4List/setRange_A06_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int16List.fromList([1, 2, 3, 4]);
Float32x4List floats = Float32x4List(4);
Expect.throws(() {
(floats as dynamic).setRange(0, 4, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float32x4List/setRange_A06_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int64List.fromList([1, 2, 3, 4]);
Float32x4List floats = Float32x4List(4);
Expect.throws(() {
(floats as dynamic).setRange(0, 4, ints);
});
}
27 changes: 27 additions & 0 deletions LibTest/typed_data/Float64List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test list elements of the same size
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
List<num> ints = Uint64List.fromList([1, 2, 3, 4]);
Float64List floats = Float64List(4);
Expect.throws(() {
// Check that it's no memcopy of the same-sized data
(floats as List<num>).setRange(0, 4, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float64List/setRange_A06_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
List<num> ints = Uint32List.fromList([1, 2, 3, 4]);
Float64List floats = Float64List(4);
Expect.throws(() {
(floats as List<num>).setRange(0, 4, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float64List/setRange_A06_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int32x4List.fromList([Int32x4(1, 1, 1, 1), Int32x4(2, 2, 2, 2)]);
Float64List floats = Float64List(2);
Expect.throws(() {
(floats as dynamic).setRange(0, 2, ints);
});
}
27 changes: 27 additions & 0 deletions LibTest/typed_data/Float64x2List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test list elements of the same size
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int32x4List.fromList([Int32x4(1, 1, 1, 1), Int32x4(2, 2, 2, 2)]);
Float64x2List floats = Float64x2List(2);
Expect.throws(() {
// Check that it's no memcopy of the same-sized data
(floats as dynamic).setRange(0, 2, ints);
});
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Float64x2List/setRange_A06_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` is not subtype of this list. Test less-sized list elements
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var ints = Int64List.fromList([1, 2, 3, 4]);
Float64x2List floats = Float64x2List(4);
Expect.throws(() {
(floats as dynamic).setRange(0, 4, ints);
});
}
31 changes: 31 additions & 0 deletions LibTest/typed_data/Int16List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is not an error if run-time type of the
/// `iterable` elements is an integer
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
Uint8List uint8List = Uint8List.fromList([255, 255]);
Uint16List uint16List = Uint16List.fromList([0xFFFF, 1]);
Uint32List uint32List = Uint32List.fromList([0xFFFFFFFF, 2]);
Int16List int16List = Int16List(2);
int16List.setRange(0, 2, uint8List);
Expect.listEquals([255, 255], int16List);
int16List.setRange(0, 2, uint16List);
Expect.listEquals([-1, 1], int16List);
int16List.setRange(0, 2, uint32List);
Expect.listEquals([-1, 2], int16List);
}
26 changes: 26 additions & 0 deletions LibTest/typed_data/Int16List/setRange_A06_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is a run time error if run-time type of the
/// `iterable` elements is not a subtype of `Int16`
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
var floats = Float32List.fromList([1, 2, 3, 4]);
Int16List int16List = Int16List(4);
Expect.throws(() {
(int16List as dynamic).setRange(0, 4, floats);
});
}
28 changes: 28 additions & 0 deletions LibTest/typed_data/Int32List/setRange_A06_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// @assertion
/// void setRange(
/// int start,
/// int end,
/// Iterable<E> iterable, [
/// int skipCount = 0
/// ])
///
/// @description Checks that it is not an error if run-time type of the
/// `iterable` elements is an integer
/// @author [email protected]
import "dart:typed_data";
import "../../../Utils/expect.dart";

void main() {
Uint16List uint16List = Uint16List.fromList([0xFFFF, 1]);
Uint32List uint32List = Uint32List.fromList([0xFFFFFFFF, 2]);
Int32List int32List = Int32List(2);
int32List.setRange(0, 2, uint16List);
Expect.listEquals([65535, 1], int32List);
int32List.setRange(0, 2, uint32List);
Expect.listEquals([-1, 2], int32List);
}
Loading

0 comments on commit af60144

Please sign in to comment.