// 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; /// Whether the tests run compiled to JavaScript. const isWeb = identical(0, 0.0); List listOf(Object? v) => (v! as List).cast(); /// 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 draws = []; @override void fill(Uint8List out) { _inner.fill(out); draws.add(Uint8List.fromList(out)); } /// The draws as the vectors write them. List 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));