<commit_before>var test = require('tape');

var Spec = require('./lib/amf/spec.js');
var Stream = require('./lib/io/stream.js');
var InputStream = require('./lib/io/input.js');
var OutputStream = require('./lib/io/output.js');
var AMF = require('./lib/amf/amf.js');

test('undefined', function(t) {
  t.plan(1);

  t.equal(AMF.deserialize(AMF.serialize()), undefined);
});

test('null', function(t) {
  t.plan(1);

  t.equal(AMF.deserialize(AMF.serialize(null)), null);
});

test('false', function(t) {
  t.plan(1);

  t.equal(AMF.deserialize(AMF.serialize(false)), false);
});

test('true', function(t) {
  t.plan(1);

  t.equal(AMF.deserialize(AMF.serialize(true)), true);
});

test('int', function(t) {

  var samples = [5, 100, -100, Spec.MIN_INT, Spec.MAX_INT, -109876983];
  t.plan(samples.length + 1);

  for(var i in samples) {
    var sample = samples[i];
    t.equal(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_INT)), sample);
  }

  t.throws(function() {
    AMF.serialize(Spec.MAX_INT + 1, true, Spec.AMF3_INT);
  }, RangeError, 'should throw RangeError');

});

test('double', function(t) {

  var samples = [-10, 0.3767574, Spec.MIN_INT, Spec.MAX_INT, Math.PI, Number.MAX_VALUE, Number.MIN_VALUE, 102.145];
  t.plan(samples.length);

  for(var i in samples) {
    var sample = samples[i];
    t.equal(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_DOUBLE), Spec.AMF3_DOUBLE), sample);
  }
});

test('string', function(t) {

  var bigString = '';
  for(var i = 0; i < (Math.random() * 9999999) + 100000; i++) {
    bigString += String.fromCharCode(Math.round(Math.random() * 91) + 65);
  }

  var samples = ['hello!', '', '.', 'ünicødé s†®îng', bigString];
  t.plan(samples.length);

  for(var s in samples) {
    var sample = samples[s];
    t.equal(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_STRING)), sample);
  }
});

test('date', function(t) {

  var samples = [new Date(), new Date(2011, 3, 9), new Date(1843, 1, 9), new Date(254, 1, 9), new Date(2040, 5, 12)];
  t.plan(samples.length);

  for(var i in samples) {
    var sample = samples[i];
    var data = AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_DATE));
    t.equal(data.getTime(), sample.getTime());
  }
});

/**
 * Convert an ascii string to hex
 *
 * @param x
 * @returns {string}
 */
var toHex = function(x) {
  var hex = '';
  for(var i= 0; i < x.length; i++) {
    var byte = parseInt((x.substr(i, 1)).charCodeAt(0)).toString(16);
    hex += byte.paddingLeft('00');
  }

  return hex;
};
<commit_msg>Changed tape test method to "same" - better equivalency<commit_after>var test = require('tape');

var Spec = require('./lib/amf/spec.js');
var Stream = require('./lib/io/stream.js');
var InputStream = require('./lib/io/input.js');
var OutputStream = require('./lib/io/output.js');
var AMF = require('./lib/amf/amf.js');

test('undefined', function(t) {
  t.plan(1);

  t.same(AMF.deserialize(AMF.serialize()), undefined);
});

test('null', function(t) {
  t.plan(1);

  t.same(AMF.deserialize(AMF.serialize(null)), null);
});

test('false', function(t) {
  t.plan(1);

  t.same(AMF.deserialize(AMF.serialize(false)), false);
});

test('true', function(t) {
  t.plan(1);

  t.same(AMF.deserialize(AMF.serialize(true)), true);
});

test('int', function(t) {

  var samples = [5, 100, -100, Spec.MIN_INT, Spec.MAX_INT, -109876983];
  t.plan(samples.length + 1);

  for(var i in samples) {
    var sample = samples[i];
    t.same(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_INT)), sample);
  }

  t.throws(function() {
    AMF.serialize(Spec.MAX_INT + 1, true, Spec.AMF3_INT);
  }, RangeError, 'should throw RangeError');

});

test('double', function(t) {

  var samples = [-10, 0.3767574, Spec.MIN_INT, Spec.MAX_INT, Math.PI, Number.MAX_VALUE, Number.MIN_VALUE, 102.145];
  t.plan(samples.length);

  for(var i in samples) {
    var sample = samples[i];
    t.same(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_DOUBLE), Spec.AMF3_DOUBLE), sample);
  }
});

test('string', function(t) {

  var bigString = '';
  for(var i = 0; i < (Math.random() * 9999999) + 100000; i++) {
    bigString += String.fromCharCode(Math.round(Math.random() * 91) + 65);
  }

  var samples = ['hello!', '', '.', 'ünicødé s†®îng', bigString];
  t.plan(samples.length);

  for(var s in samples) {
    var sample = samples[s];
    t.same(AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_STRING)), sample);
  }
});

test('date', function(t) {

  var samples = [new Date(), new Date(2011, 3, 9), new Date(1843, 1, 9), new Date(254, 1, 9), new Date(2040, 5, 12)];
  t.plan(samples.length);

  for(var i in samples) {
    var sample = samples[i];
    var data = AMF.deserialize(AMF.serialize(sample, true, Spec.AMF3_DATE));
    t.same(data, sample);
  }
});

/**
 * Convert an ascii string to hex
 *
 * @param x
 * @returns {string}
 */
var toHex = function(x) {
  var hex = '';
  for(var i= 0; i < x.length; i++) {
    var byte = parseInt((x.substr(i, 1)).charCodeAt(0)).toString(16);
    hex += byte.paddingLeft('00');
  }

  return hex;
};

{'fraction_non_alphanumeric': 0.203601108033241, 'fraction_numerical': 0.036802532647407994, 'mean_word_length': 3.8982558139534884, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '839056', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1921, 'n_words': 397}