<commit_before>var should = require('chai').should()

var matches = require('./../src/z');

describe('tests with ES6', function () {
  it('should match head of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).head().should.equal('a')
  });

  it('should match tail of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).tail().should.eql(['b', 'c', 'd', 'e'])
  });

  it('should match last of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).last().should.equal('e')
  });

  it('should match init of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).init().should.eql(['a', 'b', 'c', 'd'])
  });

  it('should map an array', function () {
    var $map = (numbers, f) => {
      return numbers.matches(
        (_, xs = []) => [],
        (x, xs)      => [f(x)].concat(xs.map(f))
      )
    };

    $map([1, 2, 3, 4, 5], number => number * 2).should.eql([2, 4, 6 , 8, 10])
  });

  it('should use 3 positions of pattern matching', function(){
    var compress = (numbers) => {
      return numbers.matches(
        (x) => [x],
        (x, y, xs) => (x == y) ? compress([x].concat(xs)) : [x].concat(compress([y].concat(xs)))
      )
    }

    compress([1, 1 , 2, 3, 3, 3]).should.eql([1, 2, 3])
  })

  it('should map a constant', function (){
    'h'.matches(
      (x = 'h') => true,
      (x)       => false
    ).should.equal(true);
  });

  it('should map a constant 2', function (){
    'a'.matches(
      (x = 'h') => true,
      (x)       => false
    ).should.equal(false);
  });

  it('should map a constant 3', function (){
    var factorial = function(number) {
      return number.matches(
        function(x){ return (x == 0) ? 1 : x * factorial (x - 1) }
      )
    }
  });

  it('should reverse a list', function (){

    var myReverse = (list) => {
      return list.matches(
        ()           => [],                          //match list ending
        (head, tail) => myReverse(tail).concat(head) //creates a reversed list recursively
      )
    }


    myReverse([1, 2, 3, 4, 5]).should.eql([5, 4, 3, 2, 1]);
  });

  it('should reverse a list2', function (){

    var myReverse = function(list) {
      return list.matches(
        function(){ return [] },
        function(head, tail){ return myReverse(tail).concat(head) }
      )
    }

    myReverse([1, 2, 3, 4, 5]).should.eql([5, 4, 3, 2, 1]);
  });

});<commit_msg>add new test<commit_after>var should = require('chai').should()

var matches = require('./../src/z');

describe('tests with ES6', function () {
  it('should match head of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).head().should.equal('a')
  });

  it('should match tail of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).tail().should.eql(['b', 'c', 'd', 'e'])
  });

  it('should match last of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).last().should.equal('e')
  });

  it('should match init of an array', function () {
    (['a', 'b', 'c', 'd', 'e']).init().should.eql(['a', 'b', 'c', 'd'])
  });

  it('should map an array', function () {
    var $map = (numbers, f) => {
      return numbers.matches(
        (_, xs = []) => [],
        (x, xs)      => [f(x)].concat(xs.map(f))
      )
    };

    $map([1, 2, 3, 4, 5], number => number * 2).should.eql([2, 4, 6 , 8, 10])
  });

  it('should use 3 positions of pattern matching', function(){
    var compress = (numbers) => {
      return numbers.matches(
        (x) => [x],
        (x, y, xs) => (x == y) ? compress([x].concat(xs)) : [x].concat(compress([y].concat(xs)))
      )
    }

    compress([1, 1 , 2, 3, 3, 3]).should.eql([1, 2, 3])
  })

  it('should map a constant', function (){
    'h'.matches(
      (x = 'h') => true,
      (x)       => false
    ).should.equal(true);
  });

  it('should map a constant 2', function (){
    'a'.matches(
      (x = 'h') => true,
      (x)       => false
    ).should.equal(false);
  });

  it('should map a constant 3', function (){
    var factorial = function(number) {
      return number.matches(
        function(x){ return (x == 0) ? 1 : x * factorial (x - 1) }
      )
    }
  });

  it('should reverse a list', function (){

    var myReverse = (list) => {
      return list.matches(
        ()           => [],                          //match list ending
        (head, tail) => myReverse(tail).concat(head) //creates a reversed list recursively
      )
    }


    myReverse([1, 2, 3, 4, 5]).should.eql([5, 4, 3, 2, 1]);
  });

  it('should reverse a list2', function (){

    var myReverse = function(list) {
      return list.matches(
        function(){ return [] },
        function(head, tail){ return myReverse(tail).concat(head) }
      )
    }

    myReverse([1, 2, 3, 4, 5]).should.eql([5, 4, 3, 2, 1]);
  });

  it.only('should match array of arrays', function(){
    var matched = false;

    [1, 2, [3]].matches(
        (x = Array) => {matched = true},
        (x) => {console.log("here", x)}
    );

    matched.should.eql(true);

  });

});
{'fraction_non_alphanumeric': 0.23400842189693202, 'fraction_numerical': 0.020252656907960697, 'mean_word_length': 2.301125082726671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7167835', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1749, 'n_words': 464}