<commit_before>'use strict';

const expect = require('chai').expect;
const miteApi = require('./mite-api');
const config = require('./../mite-config');

describe('mite-api wrapper', () => {

  const mite = new miteApi(config);

  describe('sort', () => {
    it('throws an error when items is not an array', () => {
      expect(() => {
        mite.sort(true, false);
      }).to.throw(Error);
    });
    it('throws an error when attribute is not a string', () => {
      expect(() => {
        mite.sort([{a: 'b'}], false);
      }).to.throw(Error);
    });

    describe('multiple attributes', () => {
      const items = [
        { archived: true, name: 'Beta' },
        { archived: false, name: 'xanibe' },
        { archived: true, name: 'Alpha' },
        { archived: true, name: 'Ceta' },
        { archived: false, name: 'Ceta' },
        { archived: false, name: 'Custom' },
        { archived: false, name: 'Freebie' },
      ];
      it('can handle multiple also descending attribute', () => {
        const result = mite.sort(items, ['archived', 'name']);
        expect(result).to.deep.equal([
          { archived: true, name: 'Alpha' },
          { archived: true, name: 'Beta' },
          { archived: true, name: 'Ceta' },
          { archived: false, name: 'Ceta' },
          { archived: false, name: 'Custom' },
          { archived: false, name: 'Freebie' },
          { archived: false, name: 'xanibe' },
        ]);
      });
      it('returns the items ordered correctly', () => {
        const result = mite.sort(items, ['-archived', 'name']);
        expect(result).to.deep.equal([
          { archived: false, name: 'Ceta' },
          { archived: false, name: 'Custom' },
          { archived: false, name: 'Freebie' },
          { archived: false, name: 'xanibe' },
          { archived: true, name: 'Alpha' },
          { archived: true, name: 'Beta' },
          { archived: true, name: 'Ceta' },
        ]);
      });
    });

    describe('string values', () => {
      it('returns the array sorted case-insensitive by the given attribute using string comparison', () => {
        const items = [
          { name: 'Xavier' },
          { name: 'Magneto' },
          { name: 'MYstique' },
        ];
        const result = mite.sort(items, 'name');
        expect(result.map(v => v.name)).to.deep.equal(['Magneto', 'MYstique', 'Xavier']);
      });
    }); // string comparison

    describe('numeric comparison', () => {
      it('returns the array ordered by numeric value in ascending order', () => {
        const items = [
          { value: 198.18 },
          { value: -1.21 },
          { value: 2 }
        ];
        const result = mite.sort(items, 'value');
        expect(result.map(v => v.value)).to.deep.equal([-1.21, 2, 198.18]);
      });
    }); // string comparison

    describe('boolean comparison', () => {
      it('returns the array ordered by numeric value in ascending order', () => {
        const items = [
          { value: false },
          { value: true },
          { value: false }
        ];
        const result = mite.sort(items, 'value');
        expect(result.map(v => v.value)).to.deep.equal([true, false, false]);<commit_msg>test: fixed call to sort method<commit_after>'use strict';

const expect = require('chai').expect;
const miteApi = require('./mite-api');
const config = require('./../mite-config');

describe('mite-api wrapper', () => {

  const mite = new miteApi(config);

  describe('sort', () => {
    it('throws an error when items is not an array', () => {
      expect(() => {
        mite.sort(true, false);
      }).to.throw(Error);
    });
    it('throws an error when attribute is not a string', () => {
      expect(() => {
        mite.sort([{a: 'b'}], false);
      }).to.throw(Error);
    });

    describe('multiple attributes', () => {
      const items = [
        { archived: true, name: 'Beta' },
        { archived: false, name: 'xanibe' },
        { archived: true, name: 'Alpha' },
        { archived: true, name: 'Ceta' },
        { archived: false, name: 'Ceta' },
        { archived: false, name: 'Custom' },
        { archived: false, name: 'Freebie' },
      ];
      it('can handle multiple also descending attribute', () => {
        const result = mite.sort(items, ['archived', 'name']);
        expect(result).to.deep.equal([
          { archived: true, name: 'Alpha' },
          { archived: true, name: 'Beta' },
          { archived: true, name: 'Ceta' },
          { archived: false, name: 'Ceta' },
          { archived: false, name: 'Custom' },
          { archived: false, name: 'Freebie' },
          { archived: false, name: 'xanibe' },
        ]);
      });
      it('returns the items ordered correctly', () => {
        const result = mite.sort(items, ['-archived', 'name']);
        expect(result).to.deep.equal([
          { archived: false, name: 'Ceta' },
          { archived: false, name: 'Custom' },
          { archived: false, name: 'Freebie' },
          { archived: false, name: 'xanibe' },
          { archived: true, name: 'Alpha' },
          { archived: true, name: 'Beta' },
          { archived: true, name: 'Ceta' },
        ]);
      });
    });

    describe('string values', () => {
      it('returns the array sorted case-insensitive by the given attribute using string comparison', () => {
        const items = [
          { name: 'Xavier' },
          { name: 'Magneto' },
          { name: 'MYstique' },
        ];
        const result = mite.sort(items, ['name']);
        expect(result.map(v => v.name)).to.deep.equal(['Magneto', 'MYstique', 'Xavier']);
      });
    }); // string comparison

    describe('numeric comparison', () => {
      it('returns the array ordered by numeric value in ascending order', () => {
        const items = [
          { value: 198.18 },
          { value: -1.21 },
          { value: 2 }
        ];
        const result = mite.sort(items, ['value']);
        expect(result.map(v => v.value)).to.deep.equal([-1.21, 2, 198.18]);
      });
    }); // string comparison

    describe('boolean comparison', () => {
      it('returns the array ordered by numeric value in ascending order', () => {
        const items = [
          { value: false },
          { value: true },
          { value: false }
        ];
        const result = mite.sort(items, ['value']);
        expect(result.map(v => v.value)).to.deep.equal([true, false, false]);
{'fraction_non_alphanumeric': 0.18516791044776118, 'fraction_numerical': 0.005597014925373134, 'mean_word_length': 2.1077294685990338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '2199995', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1930, 'n_words': 496}