You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dateKeys-dart/test/random_support.dart

41 lines
1.2 KiB

// Helpers of the tests of the random sources and of the age writer: the
// deterministic source of a seed named as the vectors name it, and a source
// that records the draws of another one. They read no file.
import 'dart:typed_data';
import 'package:datekeys/datekeys.dart' show toHex;
import 'package:datekeys/src/bytes.dart' show utf8Bytes;
import 'package:datekeys/src/random.dart';
typedef Json = Map<String, Object?>;
/// Whether the tests run compiled to JavaScript.
const isWeb = identical(0, 0.0);
List<Json> listOf(Object? v) => (v! as List).cast<Json>();
/// A source that records every draw of another one: its size and bytes.
final class RecordingSource implements RandomSource {
RecordingSource(this._inner);
final RandomSource _inner;
/// The draws, in order.
final List<Uint8List> draws = [];
@override
void fill(Uint8List out) {
_inner.fill(out);
draws.add(Uint8List.fromList(out));
}
/// The draws as the vectors write them.
List<Json> get json => [
for (final d in draws) {'n': d.length, 'hex': toHex(d)},
];
}
/// The deterministic source of [seed], a string, as the vectors name it.
SeededRandomSource seeded(String seed) => SeededRandomSource(utf8Bytes(seed));

Powered by TurnKey Linux.