<commit_before>var Variable  = require('../../base/variable');
var expect = require('chai').expect;
var moment = require('moment');

var v1 = new Variable([2.12, -12.2, 3, undefined]);
var v2 = new Variable(['2.12', '-12.2','3']);
var v3 = new Variable(['2.12', '-12.2', ,'3'], { mode: 'string' });
var v4 = new Variable([true, false, , true]);
var v5 = new Variable(['23-10-2007', '22-09-2008'], { mode: 'date', format: 'DD-MM-YYYY' });
var v6 = new Variable(['A', 'A', 'B', 'D'], { mode: 'ord', levels: ['C', 'A', 'D', 'B'] });

describe('Variable get', function() {
   it('exists', function() {
      expect(Variable).to.respondTo('get');
      expect(v1.get(2)).to.equal(-12.2);
      expect(v1.get([1, 2])).to.deep.equal([2.12, -12.2]);
      expect(v1.get(4)).to.not.exist;
      expect(v3.get(3)).to.not.exist;
      expect(v4.get(3)).to.not.exist;
      expect(v4.get(4)).to.equal(true);
   });
   it('returns null when out of bounds', function() {
      expect(v1.get(0)).to.not.exist;
      expect(v1.get(5)).to.not.exist;
   });
   it('works for factors and ordered', function() {
      expect(v2.get(0)).to.not.exist;
      expect(v2.get(5)).to.not.exist;
      expect(v2.get(3)).to.equal('3');
      expect(v6.get(2)).to.equal('A');
      expect(v6.get(3)).to.equal('B');
      expect(v6.get(4)).to.equal('D');
      expect(v6.get([2, 3])).to.deep.equal(['A', 'B']);
      expect(v6.get()).to.deep.equal(['A', 'A', 'B', 'D']);
   });
   it('works for datetime', function() {
      expect(moment(v5.get(1)).year()).to.equal(2007);
      expect(moment(v5.get(1)).month()).to.equal(9);
      expect(moment(v5.get(1)).date()).to.equal(23);
      expect(v5.get(0)).to.not.exist;
      expect(v5.get([1, 2])).to.exist;
      expect(v5.get([1, 2]).length).to.equal(2);
   });
});<commit_msg>Add test for out-of-bounds within #get array<commit_after>var Variable  = require('../../base/variable');
var expect = require('chai').expect;
var moment = require('moment');

var v1 = new Variable([2.12, -12.2, 3, undefined]);
var v2 = new Variable(['2.12', '-12.2','3']);
var v3 = new Variable(['2.12', '-12.2', ,'3'], { mode: 'string' });
var v4 = new Variable([true, false, , true]);
var v5 = new Variable(['23-10-2007', '22-09-2008'], { mode: 'date', format: 'DD-MM-YYYY' });
var v6 = new Variable(['A', 'A', 'B', 'D'], { mode: 'ord', levels: ['C', 'A', 'D', 'B'] });

describe('Variable get', function() {
   it('exists', function() {
      expect(Variable).to.respondTo('get');
      expect(v1.get(2)).to.equal(-12.2);
      expect(v1.get([1, 2])).to.deep.equal([2.12, -12.2]);
      expect(v1.get([1, 5, 2])).to.deep.equal([2.12, null, -12.2]);
      expect(v1.get(4)).to.not.exist;
      expect(v3.get(3)).to.not.exist;
      expect(v4.get(3)).to.not.exist;
      expect(v4.get(4)).to.equal(true);
   });
   it('returns null when out of bounds', function() {
      expect(v1.get(0)).to.not.exist;
      expect(v1.get(5)).to.not.exist;
   });
   it('works for factors and ordered', function() {
      expect(v2.get(0)).to.not.exist;
      expect(v2.get(5)).to.not.exist;
      expect(v2.get(3)).to.equal('3');
      expect(v6.get(2)).to.equal('A');
      expect(v6.get(3)).to.equal('B');
      expect(v6.get(4)).to.equal('D');
      expect(v6.get([2, 3])).to.deep.equal(['A', 'B']);
      expect(v6.get()).to.deep.equal(['A', 'A', 'B', 'D']);
   });
   it('works for datetime', function() {
      expect(moment(v5.get(1)).year()).to.equal(2007);
      expect(moment(v5.get(1)).month()).to.equal(9);
      expect(moment(v5.get(1)).date()).to.equal(23);
      expect(v5.get(0)).to.not.exist;
      expect(v5.get([1, 2])).to.exist;
      expect(v5.get([1, 2]).length).to.equal(2);
   });
});
{'fraction_non_alphanumeric': 0.27321960465746004, 'fraction_numerical': 0.06119685892228541, 'mean_word_length': 3.3305978898007034, 'pattern_counts': {'":': 0, '<': 3, '<?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': '898825', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1456, 'n_words': 235}