2026-05-09 20:19:31 +07:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
2026-04-21 03:15:20 +05:30
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
|
|
|
|
|
|
class TestUtils {
|
2026-05-09 20:19:31 +07:00
|
|
|
static final _random = Random();
|
|
|
|
|
|
2026-04-21 03:15:20 +05:30
|
|
|
static String uuid([String? id]) => id ?? const Uuid().v4();
|
|
|
|
|
|
|
|
|
|
static DateTime date([DateTime? date]) => date ?? DateTime.now();
|
|
|
|
|
static DateTime now() => DateTime.now();
|
|
|
|
|
static DateTime yesterday() => DateTime.now().subtract(const Duration(days: 1));
|
|
|
|
|
static DateTime tomorrow() => DateTime.now().add(const Duration(days: 1));
|
2026-05-09 20:19:31 +07:00
|
|
|
|
|
|
|
|
static T randElement<T>(List<T> list) => list[_random.nextInt(list.length)];
|
|
|
|
|
static int randInt([int? max]) => max != null ? _random.nextInt(max) : _random.nextInt(1 << 32);
|
|
|
|
|
static double randDouble([int? max, int? min]) {
|
|
|
|
|
final minValue = min ?? 0;
|
|
|
|
|
final maxValue = max ?? 1;
|
|
|
|
|
return minValue + _random.nextDouble() * (maxValue - minValue);
|
|
|
|
|
}
|
2026-04-21 03:15:20 +05:30
|
|
|
}
|