Files
sdk/samples/sample_extension/test_sample_asynchronous_extension.dart
T
Leaf Petersen 745f112ef6 Opt out some files from null safety.
Opt an initial batch of files under samples, samples-dev,
utils, and runtime/tools/dartfuzz out of null safety in preparation
for switching the flag on by default.

Change-Id: Icdfd52a5a969e678a7205903332f73fe3841c223
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166960
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2020-10-12 22:15:42 +00:00

61 lines
1.7 KiB
Dart

// Copyright (c) 2012, 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.
// @dart = 2.9
library test_sample_extension;
import 'sample_asynchronous_extension.dart';
void check(bool condition, String message) {
if (!condition) {
throw new StateError(message);
}
}
void main() {
RandomArray r = new RandomArray();
r.randomArray(17, 100).then((list_100) {
r.randomArray(17, 200).then((list_200) {
for (var i = 0; i < 100; ++i) {
check(list_100[i] == list_200[i], "list_100[i] == list_200[i]");
}
});
});
// Gets a list of 256000 random uint8 values, using seed 19, and
// runs checkNormal on that list.
r.randomArray(19, 256000).then(checkNormal);
}
void checkNormal(List l) {
// Count how many times each byte value occurs. Assert that the counts
// are all within a reasonable (six-sigma) range.
List counts = new List<int>.filled(256, 0);
for (var e in l) {
counts[e]++;
}
new RandomArray().randomArray(18, 256000).then(checkCorrelation(counts));
}
Function checkCorrelation(List counts) {
return (List l) {
List counts_2 = new List<int>.filled(256, 0);
for (var e in l) {
counts_2[e]++;
}
var product = 0;
for (var i = 0; i < 256; ++i) {
check(counts[i] < 1200, "counts[i] < 1200");
check(counts_2[i] < 1200, "counts_2[i] < 1200");
check(counts[i] > 800, "counts[i] > 800");
check(counts[i] > 800, "counts[i] > 800");
product += counts[i] * counts_2[i];
}
check(product < 256000000 * 1.001, "product < 256000000 * 1.001");
check(product > 256000000 * 0.999, "product > 256000000 * 0.999");
};
}