<commit_before>/**
 * PUSH Notification server
 * (c) Telefonica Digital, 2012 - All rights reserved
 * License: GNU Affero V3 (see LICENSE file)
 * <NAME> <<EMAIL>>
 * <NAME> <<EMAIL>>
 */

var assert = require('assert'),
    vows = require('vows'),
    token = require('../../src/common/token');
    common = require('../functional/common');

//Internal vars
var NUM_TOKENS = 50000;
var tokens = [];
//Get a lot of tokens
(function getTokens() {
  for (var i = NUM_TOKENS; i > 0; i--) {
    tokens.push(token.get());
  }
  return tokens;
})();

function verifyTokens() {
  tokens.forEach(function(element) {
    token.verify(element);
  });
}

function setCharAt(str,index,chr) {
  if(index > str.length-1) return str;
  return str.substr(0,index) + chr + str.substr(index+1);
}

var tokensModified = [];
//Get tokens, and modify it
(function getTokensAndMofify() {
  var tokenito = '';
  var length = 0;
  var tokenitoAfter = '';
  for (var i = 1000; i > 0; i--) {
    tokenito = token.get();
    length = tokenito.length-1;
    tokenitoAfter = tokenito;
    tokenitoAfter = setCharAt(tokenito,
                              tokenito.length-1,
                              String.fromCharCode(tokenito.charCodeAt(length-1) +
                                                  Math.floor(Math.random()*11)));
    tokensModified.push(tokenitoAfter);
  }
  return tokensModified;
})();



// TESTS //
vows.describe('Token tests').addBatch({
  /**
   * Ask for NUM_TOKENS tokens. Should be all different
   */
  'Getting a lot of tokens': {
    topic: tokens,
    'we should have NUM_TOKENS elements': function(topic) {
      assert.equal(topic.length, NUM_TOKENS);<commit_msg>Fixed modify tokens unit test<commit_after>/**
 * PUSH Notification server
 * (c) Telefonica Digital, 2012 - All rights reserved
 * License: GNU Affero V3 (see LICENSE file)
 * <NAME> <<EMAIL>>
 * <NAME> <<EMAIL>>
 */

var assert = require('assert'),
    vows = require('vows'),
    token = require('../../src/common/token');
    common = require('../functional/common');

//Internal vars
var NUM_TOKENS = 50000;
var tokens = [];
//Get a lot of tokens
(function getTokens() {
  for (var i = NUM_TOKENS; i > 0; i--) {
    tokens.push(token.get());
  }
  return tokens;
})();

function verifyTokens() {
  tokens.forEach(function(element) {
    token.verify(element);
  });
}

function setCharAt(str,index,chr) {
  if(index > str.length-1) return str;
  return str.substr(0,index) + chr + str.substr(index+1);
}

var tokensModified = [];
//Get tokens, and modify it
(function getTokensAndMofify() {
  var tokenito = '';
  var length = 0;
  var tokenitoAfter = '';
  for (var i = tokenito.length; i > 0; i--) {
    tokenito = token.get();
    length = tokenito.length-1;
    tokenitoAfter = tokenito;
    tokenitoAfter = setCharAt(tokenito,
                              tokenito.length-i,
                              String.fromCharCode(tokenito.charCodeAt(length-1) +
                                                  Math.floor(Math.random()*11)));
    tokensModified.push(tokenitoAfter);
  }
  return tokensModified;
})();



// TESTS //
vows.describe('Token tests').addBatch({
  /**
   * Ask for NUM_TOKENS tokens. Should be all different
   */
  'Getting a lot of tokens': {
    topic: tokens,
    'we should have NUM_TOKENS elements': function(topic) {
      assert.equal(topic.length, NUM_TOKENS);
{'fraction_non_alphanumeric': 0.15182006510802012, 'fraction_numerical': 0.013317549570878958, 'mean_word_length': 2.6980306345733043, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2848334', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1075, 'n_words': 267}