<commit_before>"use strict";

var Hashring = require('../');

describe('HashRing', function () {
  it('exposes the library version', function () {
    Hashring.version.should.match(/^\d+\.\d+\.\d+$/);
  });

  it('libmemcached compatiblity', function () {
    var ring = new Hashring({
      '10.0.1.1:11211': 600,
      '10.0.1.2:11211': 300,
      '10.0.1.3:11211': 200,
      '10.0.1.4:11211': 350,
      '10.0.1.5:11211': 1000,
      '10.0.1.6:11211': 800,
      '10.0.1.7:11211': 950,
      '10.0.1.8:11211': 100
    });

    // VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets us
    // test the boundary wraparound.
    ring.find(ring.hashValue('VDEAAAAA')).should.equal(0);
  });

  describe('API', function () {
    it('constructs with a string', function () {
      var ring = new Hashring('192.168.0.102:11212');

      ring.servers.should.have.length(1);
      ring.ring.length.should.be.above(1);
    });

    it('constructs with a array', function () {
      var ring = new Hashring([
          '192.168.0.102:11212'
        , '192.168.0.103:11212'
        , '192.168.0.104:11212'
      ]);

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.above(1);
    });

    it('constructs with a object', function () {
      var ring = new Hashring({
          '192.168.0.102:11212': 2
        , '192.168.0.103:11212': 2
        , '192.168.0.104:11212': 2
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.above(1);

      ring.servers.forEach(function (server) {
        server.weight.should.be.above(1);
      });
    });

    it('constructs with a object with per node vnodes', function () {
      var ring = new Hashring({
          '192.168.0.102:11212': { 'vnodes': 40 }
        , '192.168.0.103:11212': { 'vnodes': 50 }
        , '192.168.0.104:11212': { 'vnodes': 5 }
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.equal((40 + 50 + 5) * ring.replicas);

      ring = new Hashring({
          '192.168.0.102:11212': { 'vnodes': 4 }
        , '192.168.0.103:11212': { 'vnodes': 3 }
        , '192.168.0.104:11212': { 'vnodes': 5 }
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.equal((4 + 3 + 5) * 3);
    });

    it('constructs with no arguments', function () {
      var ring = new Hashring();

      ring.servers.should.have.length(0);
      ring.ring.should.have.length(0);
    });

    it('accepts different algorithms', function () {
      var ring = new Hashring('192.168.0.102:11212', 'sha1');

      ring.servers.should.have.length(1);
      ring.algorithm.should.equal('sha1');
      ring.ring.length.should.be.above(1);
    });

    it('generates the correct amount of points', function () {
      var ring = new Hashring({
          '127.0.0.1:11211': 600
        , '127.0.0.1:11212': 400
      });

      var points = ring.points();
      console.log(points['127.0.0.1:11211'].length);
    });

    describe("#add", function () {
      it('adds server after zero-argument constructor', function () {
        var ring = new Hashring();
        ring.add('192.168.0.102:11212');

        ring.servers.should.have.length(1);
        ring.ring.length.should.be.above(1);
      });
    });

    describe('#get', function () {
      it('looks up keys', function () {
        var ring = new Hashring([
            '192.168.0.102:11212'
          , '192.168.0.103:11212'
          , '192.168.0.104:11212'
        ]);

        ring.find(ring.hashValue('foo')).should.be.above(-1);
<commit_msg>[fix] Fix the node counts<commit_after>"use strict";

var Hashring = require('../');

describe('HashRing', function () {
  it('exposes the library version', function () {
    Hashring.version.should.match(/^\d+\.\d+\.\d+$/);
  });

  it('libmemcached compatiblity', function () {
    var ring = new Hashring({
      '10.0.1.1:11211': 600,
      '10.0.1.2:11211': 300,
      '10.0.1.3:11211': 200,
      '10.0.1.4:11211': 350,
      '10.0.1.5:11211': 1000,
      '10.0.1.6:11211': 800,
      '10.0.1.7:11211': 950,
      '10.0.1.8:11211': 100
    });

    // VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets us
    // test the boundary wraparound.
    ring.find(ring.hashValue('VDEAAAAA')).should.equal(0);
  });

  describe('API', function () {
    it('constructs with a string', function () {
      var ring = new Hashring('192.168.0.102:11212');

      ring.servers.should.have.length(1);
      ring.ring.length.should.be.above(1);
    });

    it('constructs with a array', function () {
      var ring = new Hashring([
          '192.168.0.102:11212'
        , '192.168.0.103:11212'
        , '192.168.0.104:11212'
      ]);

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.above(1);
    });

    it('constructs with a object', function () {
      var ring = new Hashring({
          '192.168.0.102:11212': 2
        , '192.168.0.103:11212': 2
        , '192.168.0.104:11212': 2
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.above(1);

      ring.servers.forEach(function (server) {
        server.weight.should.be.above(1);
      });
    });

    it('constructs with a object with per node vnodes', function () {
      var ring = new Hashring({
          '192.168.0.102:11212': { 'vnodes': 40 }
        , '192.168.0.103:11212': { 'vnodes': 50 }
        , '192.168.0.104:11212': { 'vnodes': 5 }
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.equal((40 + 50 + 5) * ring.replicas);

      ring = new Hashring({
          '192.168.0.102:11212': { 'vnodes': 4 }
        , '192.168.0.103:11212': { 'vnodes': 3 }
        , '192.168.0.104:11212': { 'vnodes': 5 }
      });

      ring.servers.should.have.length(3);
      ring.ring.length.should.be.equal((4 + 3 + 5) * 3);
    });

    it('constructs with no arguments', function () {
      var ring = new Hashring();

      ring.servers.should.have.length(0);
      ring.ring.should.have.length(0);
    });

    it('accepts different algorithms', function () {
      var ring = new Hashring('192.168.0.102:11212', 'sha1');

      ring.servers.should.have.length(1);
      ring.algorithm.should.equal('sha1');
      ring.ring.length.should.be.above(1);
    });

    it('generates the correct amount of points', function () {
      var ring = new Hashring({
          '127.0.0.1:11211': 600
        , '127.0.0.1:11212': 400
      });

      ring.ring.length.should.equal(160 * 2);
    });

    describe("#add", function () {
      it('adds server after zero-argument constructor', function () {
        var ring = new Hashring();
        ring.add('192.168.0.102:11212');

        ring.servers.should.have.length(1);
        ring.ring.length.should.be.above(1);
      });
    });

    describe('#get', function () {
      it('looks up keys', function () {
        var ring = new Hashring([
            '192.168.0.102:11212'
          , '192.168.0.103:11212'
          , '192.168.0.104:11212'
        ]);

        ring.find(ring.hashValue('foo')).should.be.above(-1);

{'fraction_non_alphanumeric': 0.19107921767271704, 'fraction_numerical': 0.1270578303081469, 'mean_word_length': 2.194606741573034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 57, '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': '3553724', 'n_tokens_mistral': 3093, 'n_tokens_neox': 2533, 'n_words': 432}