<commit_before>'use strict';

var assert = require('assert');

var rb_tree = require('./red-black_tree.js');

function basicTests() {
    var t = new rb_tree.Tree();

    assert(!t.has('abc'));

    t.set('abc', 5);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 5);

    t.set('abc', 7);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 7);

    t.set('def', 9);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 7);
    assert(t.has('def'));
    assert.strictEqual(t.get('def'), 9);

    t.del('abc');
    assert(!t.has('abc'));
    assert(t.has('def'));
    assert.strictEqual(t.get('def'), 9);

    t.set('ghi', 1);
    t.set('abc', 10);
    t.set('xyz', 15);

    assert.deepEqual(t.all(), [
        {key: 'abc', value: 10},
        {key: 'def', value: 9},
        {key: 'ghi', value: 1},
        {key: 'xyz', value: 15}
    ]);
}

function randomTests() {
    for (var i = 0; i < 100; i++) {
        randomTest();
    }
}

function randomTest() {
    var t = new rb_tree.Tree();
    var m = {};
    var a = [];

    for (var i = 0; i < 1000; i++) {
        var r = Math.random();
        if (r < 0.2) {
            delRandom(t, m, a);
            continue;
        }
        setRandom(t, m, a);
    }

    check(t, m, a);
}

function check(t, m, a) {
    a.forEach(function(k) {
        assert(t.has(k));
        assert.strictEqual(m[k], t.get(k));
    });

    var all = t.all();
    assert.strictEqual(a.length, all.length);
    a.sort().forEach(function(k, i) {
        assert.deepEqual(all[i], {key: k, value: m[k]});
    });<commit_msg>[red-black_tree/javascript] Shorten import name<commit_after>'use strict';

var assert = require('assert');

var rb = require('./red-black_tree.js');

function basicTests() {
    var t = new rb.Tree();

    assert(!t.has('abc'));

    t.set('abc', 5);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 5);

    t.set('abc', 7);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 7);

    t.set('def', 9);
    assert(t.has('abc'));
    assert.strictEqual(t.get('abc'), 7);
    assert(t.has('def'));
    assert.strictEqual(t.get('def'), 9);

    t.del('abc');
    assert(!t.has('abc'));
    assert(t.has('def'));
    assert.strictEqual(t.get('def'), 9);

    t.set('ghi', 1);
    t.set('abc', 10);
    t.set('xyz', 15);

    assert.deepEqual(t.all(), [
        {key: 'abc', value: 10},
        {key: 'def', value: 9},
        {key: 'ghi', value: 1},
        {key: 'xyz', value: 15}
    ]);
}

function randomTests() {
    for (var i = 0; i < 100; i++) {
        randomTest();
    }
}

function randomTest() {
    var t = new rb.Tree();
    var m = {};
    var a = [];

    for (var i = 0; i < 1000; i++) {
        var r = Math.random();
        if (r < 0.2) {
            delRandom(t, m, a);
            continue;
        }
        setRandom(t, m, a);
    }

    check(t, m, a);
}

function check(t, m, a) {
    a.forEach(function(k) {
        assert(t.has(k));
        assert.strictEqual(m[k], t.get(k));
    });

    var all = t.all();
    assert.strictEqual(a.length, all.length);
    a.sort().forEach(function(k, i) {
        assert.deepEqual(all[i], {key: k, value: m[k]});
    });
{'fraction_non_alphanumeric': 0.23007189746795872, 'fraction_numerical': 0.018755861206627072, 'mean_word_length': 2.2989690721649483, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3393973', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1201, 'n_words': 251}