<commit_before>/**
 * Created by <NAME> on 11.03.2017.
 */
/// <reference types="jasmine" />

import Range from 'phovea_core/src/range/Range';
import {SORT, numSort, stringSort, filterCat} from '../src/SortEventHandler/SortEventHandler';


function makeRangeFromList(arr) {
  const r = new Range();
  r.dim(0).pushList(arr);
  return r;
}

function mergeRanges(r: Range[]) {
  const mergedRange = r.reduce((currentVal, nextValue) => {
    const r = new Range();
    r.dim(0).pushList(currentVal.dim(0).asList().concat(nextValue.dim(0).asList()));
    return r;
  });
  return mergedRange.dim(0).asList();
}

describe('Merge Range Objects', () => {
  it('[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]', () => {
    const rangeList = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]];
    const r = rangeList.map((d) => makeRangeFromList(d));
    return expect(mergeRanges(r)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  });

  it('[[1, 2,], [3, 4], [5, 6]]', () => {
    const rangeList = [[1, 2,], [3, 4], [5, 6]];
    const r = rangeList.map((d) => makeRangeFromList(d));
    return expect(mergeRanges(r)).toEqual([1, 2, 3, 4, 5, 6]);
  });

});


describe('Sort Number', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('SORT BY ASC', () => {
    const s = arr.sort(numSort.bind(this, SORT.asc));
    return expect(s).toEqual([1, 3, 4, 5, 6, 6, 14, 15, 19]);
  });

  it('SORT BY DESC', () => {
    const s = arr.sort(numSort.bind(this, SORT.desc));
    return expect(s).toEqual([19, 15, 14, 6, 6, 5, 4, 3, 1]);
  });

});

describe('String Sort', () => {
  const arr = ['Rihanna',
    '<NAME>',
    'Madonna',
    '<NAME>',
    '<NAME>',
    'Eminem',
    '<NAME>',
    '<NAME>'];
  it('SORT BY ASC', () => {
    const s = arr.sort(stringSort.bind(this, SORT.asc));

    const expected = ['<NAME>',
      '<NAME>',
      '<NAME>',
      'Eminem',
      'Madonna',
      '<NAME>',
      'Rihanna',
      '<NAME>'];
    return expect(s).toEqual(expected);
  });

  it('STRING SORT BY DESC', () => {
    const expected = ['<NAME>',
      'Rihanna',
      '<NAME>',
      'Madonna',
      'Eminem',
      '<NAME>',
      '<NAME>',
      '<NAME>'];
    const s = arr.sort(stringSort.bind(this, SORT.desc));
    return expect(s).toEqual(expected);
  });

});


describe('Filter by Value', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('Filter by 6', () => {
    const f = arr.filter(filterCat.bind(this, 6));
    return expect(f).toEqual([6, 6]);
  });

  it('Filter by 5', () => {
    const f = arr.filter(filterCat.bind(this, 5));
    return expect(f).toEqual([5]);
  });

  it('Filter by String', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a'];
    const f = arr.filter(filterCat.bind(this, 'a'));
    return expect(f).toEqual(['a', 'a', 'a']);
  });

  it('Filter by Space', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a', ' ', ' '];
    const f = arr.filter(filterCat.bind(this, ' '));
    return expect(f).toEqual([' ', ' ']);
  });


});


function uniqueValues(allCatNames) {
  const uniqvalues = allCatNames.filter((x, i, a) => a.indexOf(x) === i);
  return uniqvalues;

}


describe('Unique Values', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('Numerical ', () => {
    return expect(uniqueValues(arr)).toEqual([1, 5, 6, 14, 3, 4, 15, 19]);
  });

  it('String', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a', ' ', ' '];
    return expect(uniqueValues(arr)).toEqual(['a', 'b', 'c', 'd', ' ']);
  });

});<commit_msg>added testing for checking number of elements in each multiforms. #214<commit_after>/**
 * Created by <NAME> on 11.03.2017.
 */
/// <reference types="jasmine" />

import Range from 'phovea_core/src/range/Range';
import {SORT, prepareRangeFromList, numSort, stringSort, filterCat} from '../src/SortEventHandler/SortEventHandler';


function makeRangeFromList(arr) {
  const r = new Range();
  r.dim(0).pushList(arr);
  return r;
}

function mergeRanges(r: Range[]) {
  const mergedRange = r.reduce((currentVal, nextValue) => {
    const r = new Range();
    r.dim(0).pushList(currentVal.dim(0).asList().concat(nextValue.dim(0).asList()));
    return r;
  });
  return mergedRange.dim(0).asList();
}

describe('Merge Range Objects', () => {
  it('[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]', () => {
    const rangeList = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]];
    const r = rangeList.map((d) => makeRangeFromList(d));
    return expect(mergeRanges(r)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  });

  it('[[1, 2,], [3, 4], [5, 6]]', () => {
    const rangeList = [[1, 2,], [3, 4], [5, 6]];
    const r = rangeList.map((d) => makeRangeFromList(d));
    return expect(mergeRanges(r)).toEqual([1, 2, 3, 4, 5, 6]);
  });

});


describe('Sort Number', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('SORT BY ASC', () => {
    const s = arr.sort(numSort.bind(this, SORT.asc));
    return expect(s).toEqual([1, 3, 4, 5, 6, 6, 14, 15, 19]);
  });

  it('SORT BY DESC', () => {
    const s = arr.sort(numSort.bind(this, SORT.desc));
    return expect(s).toEqual([19, 15, 14, 6, 6, 5, 4, 3, 1]);
  });

});

describe('String Sort', () => {
  const arr = ['Rihanna',
    '<NAME>',
    'Madonna',
    '<NAME>',
    '<NAME>',
    'Eminem',
    '<NAME>',
    '<NAME>'];
  it('SORT BY ASC', () => {
    const s = arr.sort(stringSort.bind(this, SORT.asc));

    const expected = ['<NAME>',
      '<NAME>',
      '<NAME>',
      'Eminem',
      'Madonna',
      '<NAME>',
      'Rihanna',
      '<NAME>'];
    return expect(s).toEqual(expected);
  });

  it('STRING SORT BY DESC', () => {
    const expected = ['<NAME>',
      'Rihanna',
      '<NAME>',
      'Madonna',
      'Eminem',
      '<NAME>',
      '<NAME>',
      '<NAME>'];
    const s = arr.sort(stringSort.bind(this, SORT.desc));
    return expect(s).toEqual(expected);
  });

});


describe('Filter by Value', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('Filter by 6', () => {
    const f = arr.filter(filterCat.bind(this, 6));
    return expect(f).toEqual([6, 6]);
  });

  it('Filter by 5', () => {
    const f = arr.filter(filterCat.bind(this, 5));
    return expect(f).toEqual([5]);
  });

  it('Filter by String', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a'];
    const f = arr.filter(filterCat.bind(this, 'a'));
    return expect(f).toEqual(['a', 'a', 'a']);
  });

  it('Filter by Space', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a', ' ', ' '];
    const f = arr.filter(filterCat.bind(this, ' '));
    return expect(f).toEqual([' ', ' ']);
  });


});


function uniqueValues(allCatNames) {
  const uniqvalues = allCatNames.filter((x, i, a) => a.indexOf(x) === i);
  return uniqvalues;

}


describe('Unique Values', () => {
  const arr = [1, 5, 6, 14, 3, 4, 15, 6, 19];
  it('Numerical ', () => {
    return expect(uniqueValues(arr)).toEqual([1, 5, 6, 14, 3, 4, 15, 19]);
  });

  it('String', () => {
    const arr = ['a', 'b', 'c', 'd', 'a', 'a', ' ', ' '];
    return expect(uniqueValues(arr)).toEqual(['a', 'b', 'c', 'd', ' ']);
  });

});


describe('Convert sorted range into multiforms per column', () => {
  const rangeIndexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
//Number of data elements after sorting. The length of each array means the number of multiform
  const numberOfDataElementsPerColumn = [
    [12],
    [7, 5],
    [1, 1, 1, 2, 1, 1, 2, 1, 2],
    [1, 1, 1, 2, 1, 1, 2, 1, 2]
  ];

  const expected = [[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]],
    [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11]],
    [[0], [1], [2], [3, 4], [5], [6], [7, 8], [9], [10, 11]],
    [[0], [1], [2], [3, 4], [5], [6], [7, 8], [9], [10, 11]]];

  it('Splitting multiforms ', () => {
    return expect(prepareRangeFromList(rangeIndexes, numberOfDataElementsPerColumn)).toEqual(expected);
  });

});



{'fraction_non_alphanumeric': 0.2531270148291425, 'fraction_numerical': 0.04887169568020632, 'mean_word_length': 3.060732984293194, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 81, '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': '7417663', 'n_tokens_mistral': 3326, 'n_tokens_neox': 3054, 'n_words': 772}