<commit_before>/** @license MIT License (c) copyright 2016 original author or authors */

import {describe, it} from 'mocha';
import assert from 'assert';

import { id, compose, apply } from '../src/function';

describe('id', () => {
  it('id(x) === x', () => {
    const x = {};
    assert.strictEqual(id(x), x);
  });
});

describe('compose', () => {
  it('compose(f, g)(x) === f(g(x))', () => {
    const fx = '' + Math.random();
    const gx = '' + Math.random();
    const x = '' + Math.random();

    const f = x => x + fx;
    const g = x => x + gx;
    const h = compose(f, g);

    assert.strictEqual(f(g(x)), h(x));
  });
});

describe('apply', () => {
  it('apply(f, x) === f(x)', () => {
    const x = Math.random();
    const f = x => x+1;
    assert.strictEqual(apply(f, x), f(x));
  });
});<commit_msg>test(function): add curry2 and curry3 tests<commit_after>/** @license MIT License (c) copyright 2016 original author or authors */

import {describe, it} from 'mocha';
import assert from 'assert';

import { id, compose, apply, curry2, curry3 } from '../src/function';

describe('id', () => {
  it('id(x) === x', () => {
    const x = {};
    assert.strictEqual(id(x), x);
  });
});

describe('compose', () => {
  it('compose(f, g)(x) === f(g(x))', () => {
    const fx = '' + Math.random();
    const gx = '' + Math.random();
    const x = '' + Math.random();

    const f = x => x + fx;
    const g = x => x + gx;
    const h = compose(f, g);

    assert.strictEqual(f(g(x)), h(x));
  });
});

describe('apply', () => {
  it('apply(f, x) === f(x)', () => {
    const x = Math.random();
    const f = x => x+1;
    assert.strictEqual(apply(f, x), f(x));
  });
});

describe('curry', () => {
  describe('curry2', () => {
    it('should return the original function if no args are given', () => {
      const fn = (a, b) => a + b;
      const curriedFn = curry2(fn);
      assert.strictEqual(curriedFn().length, 2);
    });

    it('should return a function of length 1 when 1 arg is given', () => {
      const fn = (a, b) => a + b;
      const curriedFn = curry2(fn);
      assert.strictEqual(curriedFn(1).length, 1);
    });

    it('should execute function when given 2 args', () => {
      const fn = (a, b) => a + b;
      const curriedFn = curry2(fn);
      assert.strictEqual(typeof curriedFn(1, 2).length, 'undefined');
      assert.strictEqual(curriedFn(1, 2), 3);
    });
  });

  describe('curry3', () => {
    it('should return the original function if no args are given', () => {
      const fn = (a, b, c) => a + b + c;
      const curriedFn = curry3(fn);
      assert.strictEqual(curriedFn().length, 3);
    });

    it('should return a function of length 2 when 1 arg is given', () => {
      const fn = (a, b, c) => a + b + c;
      const curriedFn = curry3(fn);
      assert.strictEqual(curriedFn(1).length, 2);
    });

    it('should return function of lenght 1 when given 2 args', () => {
      const fn = (a, b, c) => a + b + c;
      const curriedFn = curry3(fn);
      const addOneTwo = curriedFn(1, 2);
      assert.strictEqual(addOneTwo.length, 1);
      assert.strictEqual(addOneTwo(3), 6);
    });

    it('should execut function when given 3 args', () => {
      const fn = (a, b, c) => a + b + c;
      const curriedFn = curry3(fn);
      assert.strictEqual(typeof curriedFn(1, 2, 3).length, 'undefined');
      assert.strictEqual(curriedFn(1, 2, 3), 6);
    });
  });
});
{'fraction_non_alphanumeric': 0.21211234640140433, 'fraction_numerical': 0.01579871269748391, 'mean_word_length': 2.7779005524861877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '916527', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1198, 'n_words': 333}