validate method

void validate(
  1. LottoConfig config
)

校验与 config 的池数、数量、范围和池内唯一性;不符抛 ArgumentError。

Implementation

void validate(LottoConfig config) {
  if (numbers.length != config.pools.length) {
    throw ArgumentError.value(numbers, 'numbers', '池数量不符');
  }
  for (var p = 0; p < numbers.length; p++) {
    final pool = config.pools[p];
    final values = numbers[p];
    if (values.length != pool.count ||
        values.toSet().length != values.length ||
        values.any((n) => n < pool.min || n > pool.max)) {
      throw ArgumentError.value(values, 'numbers', '号码数量、范围或唯一性不符');
    }
  }
}