<commit_before>/* eslint-disable */
/**
 * Mnemonist TrieMap Unit Tests
 * ==========================
 */
var assert = require('assert'),
    TrieMap = require('../trie-map.js'),
    take = require('obliterator/take');

var SENTINEL = TrieMap.SENTINEL;

var inspect = require('util').inspect;

if (inspect.defaultOptions)
  inspect.defaultOptions.depth = null;

describe('TrieMap', function() {

  it('should be possible to set items into a TrieMap.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('tar', 3);

    assert.strictEqual(trie.size, 3);

    assert.strictEqual(trie.get('rat'), 1);
    assert.strictEqual(trie.get('rate'), 2);
    assert.strictEqual(trie.get('tar'), 3);
    assert.strictEqual(trie.get('show'), undefined);
    assert.strictEqual(trie.get('ra'), undefined);
    assert.strictEqual(trie.get('ratings'), undefined);

    assert.deepEqual(trie.root, {
      r: {
        a: {
          t: {
            e: {
              [SENTINEL]: 2
            },
            [SENTINEL]: 1
          }
        }
      },
      t: {
        a: {
          r: {
            [SENTINEL]: 3
          }
        }
      }
    });
  });

  it('adding the same item several times should not increase size.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('rat', 3);

    assert.strictEqual(trie.size, 2);
    assert.strictEqual(trie.get('rat'), 3);
  });

  it('should be possible to set the null sequence.', function() {
    var trie = new TrieMap();

    trie.set('', 45);
    assert.strictEqual(trie.size, 1);
    assert.strictEqual(trie.get(''), 45);

    trie = new TrieMap(Array);

    trie.set([], 45);
    assert.strictEqual(trie.size, 1);
    assert.strictEqual(trie.get([]), 45);
  });

  it('should be possible to delete items.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('tar', 3);

    assert.strictEqual(trie.delete(''), false);
    assert.strictEqual(trie.delete('hello'), false);

    assert.strictEqual(trie.delete('rat'), true);
    assert.strictEqual(trie.get('rat'), undefined);
    assert.strictEqual(trie.get('rate'), 2);

    assert.strictEqual(trie.size, 2);

    assert.deepEqual(trie.root, {
      r: {
        a: {
          t: {<commit_msg>Add unit test for TrieMap.update<commit_after>/* eslint-disable */
/**
 * Mnemonist TrieMap Unit Tests
 * ==========================
 */
var assert = require('assert'),
    TrieMap = require('../trie-map.js'),
    take = require('obliterator/take');

var SENTINEL = TrieMap.SENTINEL;

var inspect = require('util').inspect;

if (inspect.defaultOptions)
  inspect.defaultOptions.depth = null;

describe('TrieMap', function() {

  it('should be possible to set items into a TrieMap.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('tar', 3);

    assert.strictEqual(trie.size, 3);

    assert.strictEqual(trie.get('rat'), 1);
    assert.strictEqual(trie.get('rate'), 2);
    assert.strictEqual(trie.get('tar'), 3);
    assert.strictEqual(trie.get('show'), undefined);
    assert.strictEqual(trie.get('ra'), undefined);
    assert.strictEqual(trie.get('ratings'), undefined);

    assert.deepEqual(trie.root, {
      r: {
        a: {
          t: {
            e: {
              [SENTINEL]: 2
            },
            [SENTINEL]: 1
          }
        }
      },
      t: {
        a: {
          r: {
            [SENTINEL]: 3
          }
        }
      }
    });
  });

  it('adding the same item several times should not increase size.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('rat', 3);

    assert.strictEqual(trie.size, 2);
    assert.strictEqual(trie.get('rat'), 3);
  });

  it('should be possible to set the null sequence.', function() {
    var trie = new TrieMap();

    trie.set('', 45);
    assert.strictEqual(trie.size, 1);
    assert.strictEqual(trie.get(''), 45);

    trie = new TrieMap(Array);

    trie.set([], 45);
    assert.strictEqual(trie.size, 1);
    assert.strictEqual(trie.get([]), 45);
  });

  it('should be possible to update items.', function() {
    var trie = new TrieMap();

    trie.update('rat', () => 1);
    trie.update('rate', (v) => (v || 0) + 2);
    trie.update('rat', (v) => v + 3);

    assert.strictEqual(trie.size, 2);
    assert.strictEqual(trie.get('rat'), 4);
  });

  it('should be possible to delete items.', function() {
    var trie = new TrieMap();

    trie.set('rat', 1);
    trie.set('rate', 2);
    trie.set('tar', 3);

    assert.strictEqual(trie.delete(''), false);
    assert.strictEqual(trie.delete('hello'), false);

    assert.strictEqual(trie.delete('rat'), true);
    assert.strictEqual(trie.get('rat'), undefined);
    assert.strictEqual(trie.get('rate'), 2);

    assert.strictEqual(trie.size, 2);

    assert.deepEqual(trie.root, {
      r: {
        a: {
          t: {
{'fraction_non_alphanumeric': 0.19247611464968153, 'fraction_numerical': 0.013136942675159236, 'mean_word_length': 2.591851322373124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '183280', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1713, 'n_words': 348}