<commit_before>/// Run random tests against `date(1)` unix command

import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:args/args.dart';

import 'package:timezone/standalone.dart';

int minEpochTime = new DateTime.utc(1890).millisecondsSinceEpoch ~/ 1000;
int maxEpochTime = new DateTime.utc(2020).millisecondsSinceEpoch ~/ 1000;

Future<String> dateCmd(int time, String tz) {
  return Process.run(
      'date',
      ['-d', '@$time', '+%Y-%m-%d %H:%M:%S'],
      environment: {
    'TZ': tz
  }).then((r) {
    return r.stdout;
  });
}

void main(List<String> arguments) {
  // Parse CLI arguments
  final parser =
      new ArgParser()..addOption('iterations', abbr: 'i', defaultsTo: '1000');
  final argResults = parser.parse(arguments);

  final mr = maxEpochTime - minEpochTime;
  final min = minEpochTime;

  var seed = 0;
  var r = new Random(seed);
  var i = int.parse(argResults['iterations']);

  print('Seed: $seed');
  print('Iterations: $i');

  initializeTimeZone().then((_) {
    final zoneNames =
        LocationDatabase.instance.locations.keys.map((k) => k).toList();
    final zoneCount = zoneNames.length;

    Future.doWhile(() {
      final time = r.nextInt(mr) + min;
      final tz = zoneNames[r.nextInt(zoneCount)];

      return dateCmd(time, tz).then((v) {
        final x =
            new TZDateTime.fromMillisecondsSinceEpoch(getLocation(tz), time * 1000);
        v = v.trim();

        if (v != x.toString().substring(0, 19)) {
          print('Error: $tz $time $x != $v');
        }

        i--;
        return i == 0 ? false : true;
      });

    });
  });
}<commit_msg>Use logging package in test_random<commit_after>/// Run random tests against `date(1)` unix command

import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:args/args.dart';
import 'package:logging/logging.dart';
import 'package:timezone/standalone.dart';

final int minEpochTime = new DateTime.utc(1890).millisecondsSinceEpoch ~/ 1000;
final int maxEpochTime = new DateTime.utc(2020).millisecondsSinceEpoch ~/ 1000;

Future<String> dateCmd(int time, String tz) {
  return Process.run(
      'date',
      ['-d', '@$time', '+%Y-%m-%d %H:%M:%S'],
      environment: {
    'TZ': tz
  }).then((r) {
    return r.stdout;
  });
}

void main(List<String> arguments) {
  // Initialize logger
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((LogRecord rec) {
    print('${rec.level.name}: ${rec.time}: ${rec.message}');
  });
  final Logger log = new Logger('main');

  // Parse CLI arguments
  final parser = new ArgParser()
  ..addOption('iterations', abbr: 'i', defaultsTo: '1000')
  ..addOption('seed', abbr: 's', defaultsTo: '0');

  final argResults = parser.parse(arguments);

  final randomRange = maxEpochTime - minEpochTime;

  final seed = int.parse(argResults['seed']);
  var i = int.parse(argResults['iterations']);
  var r = new Random(seed);

  log.info('Seed: $seed');
  log.info('Iterations: $i');

  initializeTimeZone().then((_) {
    final zoneNames =
        LocationDatabase.instance.locations.keys.map((k) => k).toList();
    final zoneCount = zoneNames.length;

    Future.doWhile(() {
      final time = r.nextInt(randomRange) + minEpochTime;
      final tz = zoneNames[r.nextInt(zoneCount)];

      return dateCmd(time, tz).then((v) {
        final x =
            new TZDateTime.fromMillisecondsSinceEpoch(getLocation(tz), time * 1000);
        v = v.trim();

        if (v != x.toString().substring(0, 19)) {
          log.severe('$tz $time $x != $v');
        }

        i--;
        return i == 0 ? false : true;
      });

    });
  });
}
{'fraction_non_alphanumeric': 0.1715862068965517, 'fraction_numerical': 0.016551724137931035, 'mean_word_length': 3.1774193548387095, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7621304', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1202, 'n_words': 276}