<commit_before>library more.test.int_math_test;

import 'package:more/int_math.dart';
import 'package:test/test.dart';

void main() {
  test('gcd', () {
    expect(gcd(8, 12), 4);
    expect(gcd(12, 8), 4);
    expect(gcd(8, 0), 8);
    expect(gcd(0, 8), 8);
  });
  test('lcm', () {
    expect(lcm(5, 2), 10);
    expect(lcm(2, 5), 10);
    expect(lcm(5, 0), 0);
    expect(lcm(0, 5), 0);
  });
  test('factorial', () {
    expect(factorial(0), 1);
    expect(factorial(1), 1);
    expect(factorial(5), 120);
    expect(factorial(12), 479001600);
    expect(factorial(20), 2432902008176640000);
    expect(factorial(21), 2432902008176640000 * 21);
    expect(factorial(22), 2432902008176640000 * 21 * 22);
  });
  test('factorial (bounds)', () {
    expect(() => factorial(-1), throwsArgumentError);
  });
  test('binomial', () {
    expect(binomial(7, 0), 1);
    expect(binomial(7, 1), 7);
    expect(binomial(7, 2), 21);
    expect(binomial(7, 3), 35);
    expect(binomial(7, 4), 35);
    expect(binomial(7, 5), 21);
    expect(binomial(7, 6), 7);
    expect(binomial(7, 7), 1);
  });
  test('binomial (large)', () {
    Map<int, Map<int, int>> cache = {};
    int verifyBinomial(int n, int k) {
      if (k == 0 || k == n) {
        return 1;
      } else if (k == 1 || k == n - 1) {
        return n;
      } else {
        return cache
            .putIfAbsent(n, () => {})
            .putIfAbsent(k, () => verifyBinomial(n - 1, k - 1) + verifyBinomial(n - 1, k));
      }
    }
    for (var n = 0; n <= 150; n++) {
      for (var k = 0; k <= n; k++) {
        expect(binomial(n, k), verifyBinomial(n, k));
      }
    }
  });

  test('binomial (bounds)', () {
    expect(() => binomial(7, -1), throwsArgumentError);
    expect(() => binomial(7, 8), throwsArgumentError);
  });
  test('pow(x, 0)', () {
    expect(pow(-2, 0), 1);
    expect(pow(-1, 0), 1);
    expect(pow(0, 0), 1);
    expect(pow(1, 0), 1);
    expect(pow(2, 0), 1);
  });
  test('pow(x, 1)', () {
    expect(pow(-2, 1), -2);
    expect(pow(-1, 1), -1);
    expect(pow(0, 1), 0);
    expect(pow(1, 1), 1);
    expect(pow(2, 1), 2);
  });
  test('pow(x, 5)', () {
    expect(pow(-2, 5), -32);
    expect(pow(-1, 5), -1);<commit_msg>Do not run the large binomial tests in browsers, it doesn't work.<commit_after>library more.test.int_math_test;

import 'package:more/int_math.dart';
import 'package:test/test.dart';

void main() {
  test('gcd', () {
    expect(gcd(8, 12), 4);
    expect(gcd(12, 8), 4);
    expect(gcd(8, 0), 8);
    expect(gcd(0, 8), 8);
  });
  test('lcm', () {
    expect(lcm(5, 2), 10);
    expect(lcm(2, 5), 10);
    expect(lcm(5, 0), 0);
    expect(lcm(0, 5), 0);
  });
  test('factorial', () {
    expect(factorial(0), 1);
    expect(factorial(1), 1);
    expect(factorial(5), 120);
    expect(factorial(12), 479001600);
    expect(factorial(20), 2432902008176640000);
    expect(factorial(21), 2432902008176640000 * 21);
    expect(factorial(22), 2432902008176640000 * 21 * 22);
  });
  test('factorial (bounds)', () {
    expect(() => factorial(-1), throwsArgumentError);
  });
  test('binomial', () {
    expect(binomial(7, 0), 1);
    expect(binomial(7, 1), 7);
    expect(binomial(7, 2), 21);
    expect(binomial(7, 3), 35);
    expect(binomial(7, 4), 35);
    expect(binomial(7, 5), 21);
    expect(binomial(7, 6), 7);
    expect(binomial(7, 7), 1);
  });
  test('binomial (large)', () {
    Map<int, Map<int, int>> cache = {};
    int verifyBinomial(int n, int k) {
      if (k == 0 || k == n) {
        return 1;
      } else if (k == 1 || k == n - 1) {
        return n;
      } else {
        return cache
            .putIfAbsent(n, () => {})
            .putIfAbsent(k, () => verifyBinomial(n - 1, k - 1) + verifyBinomial(n - 1, k));
      }
    }
    for (var n = 0; n <= 150; n++) {
      for (var k = 0; k <= n; k++) {
        expect(binomial(n, k), verifyBinomial(n, k));
      }
    }
  }, onPlatform: {'browser': const Skip('large integers')});
  test('binomial (bounds)', () {
    expect(() => binomial(7, -1), throwsArgumentError);
    expect(() => binomial(7, 8), throwsArgumentError);
  });
  test('pow(x, 0)', () {
    expect(pow(-2, 0), 1);
    expect(pow(-1, 0), 1);
    expect(pow(0, 0), 1);
    expect(pow(1, 0), 1);
    expect(pow(2, 0), 1);
  });
  test('pow(x, 1)', () {
    expect(pow(-2, 1), -2);
    expect(pow(-1, 1), -1);
    expect(pow(0, 1), 0);
    expect(pow(1, 1), 1);
    expect(pow(2, 1), 2);
  });
  test('pow(x, 5)', () {
    expect(pow(-2, 5), -32);
    expect(pow(-1, 5), -1);
{'fraction_non_alphanumeric': 0.2327433628318584, 'fraction_numerical': 0.08893805309734513, 'mean_word_length': 2.78326359832636, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '5770389', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1783, 'n_words': 397}