<commit_before>/*
 * Given a roman numeral, convert it to an integer.
 * Input is guaranteed to be within the range from 1 to 3999.
 *
 * Tags:
 *  - Math
 *  - String
 */

/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
  var valueOf = {
    I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000
  }

  var result = 0;
  for (var i = 0; i < s.length; i++) {
    var char = s.charAt(i);
    var next = s.charAt(i + 1);
    var sign = next !== '' && valueOf[next] > valueOf[char] ? -1 : 1;
    result += sign * valueOf[char];
  }

  return result;
};

// mocha testing
var expect = require('chai').expect;
describe('Roman to Integer', function() {

  it('I ~ XX', function () {
    var input = [
      'I',   'II',   'III',   'IV',  'V',
      'VI',  'VII',  'VIII',  'IX',  'X',
      'XI',  'XII',  'XIII',  'XIV', 'XV',
      'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
    ];

    for (var i = 0; i < input.length; i++) {
      var output = romanToInt(input[i]);
      expect(output).to.equal(i + 1);
    }
  });

  it('XXI', function () {
    var input = 'XXI';
    var output = romanToInt(input);
    expect(output).to.equal(21);
  });

  it('XXIX', function () {
    var input = 'XXIX';
    var output = romanToInt(input);
    expect(output).to.equal(29);
  });

  it('XXX', function () {
    var input = 'XXX';
    var output = romanToInt(input);
    expect(output).to.equal(30);
  });

  it('XL', function () {
    var input = 'XL';
    var output = romanToInt(input);
    expect(output).to.equal(40);
  });

  it('XLVIII', function () {
    var input = 'XLVIII';
    var output = romanToInt(input);
    expect(output).to.equal(48);
  });

  it('IL', function () {
    var input = 'IL';
    var output = romanToInt(input);
    expect(output).to.equal(49);
  });

  it('L', function () {
    var input = 'L';
    var output = romanToInt(input);
    expect(output).to.equal(50);
  });

  it('LX', function () {
    var input = 'LX';
    var output = romanToInt(input);
    expect(output).to.equal(60);
  });

  it('XC', function () {
    var input = 'XC';
    var output = romanToInt(input);
    expect(output).to.equal(90);<commit_msg>[roman-to-integer] fix incorrect test case<commit_after>/*
 * Given a roman numeral, convert it to an integer.
 * Input is guaranteed to be within the range from 1 to 3999.
 *
 * Tags:
 *  - Math
 *  - String
 */

/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
  var valueOf = {
    I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000
  }

  var result = 0;
  for (var i = 0; i < s.length; i++) {
    var char = s.charAt(i);
    var next = s.charAt(i + 1);
    var sign = next !== '' && valueOf[next] > valueOf[char] ? -1 : 1;
    result += sign * valueOf[char];
  }

  return result;
};

// mocha testing
var expect = require('chai').expect;
describe('Roman to Integer', function() {

  it('I ~ XX', function () {
    var input = [
      'I',   'II',   'III',   'IV',  'V',
      'VI',  'VII',  'VIII',  'IX',  'X',
      'XI',  'XII',  'XIII',  'XIV', 'XV',
      'XVI', 'XVII', 'XVIII', 'XIX', 'XX',
    ];

    for (var i = 0; i < input.length; i++) {
      var output = romanToInt(input[i]);
      expect(output).to.equal(i + 1);
    }
  });

  it('XXI', function () {
    var input = 'XXI';
    var output = romanToInt(input);
    expect(output).to.equal(21);
  });

  it('XXIX', function () {
    var input = 'XXIX';
    var output = romanToInt(input);
    expect(output).to.equal(29);
  });

  it('XXX', function () {
    var input = 'XXX';
    var output = romanToInt(input);
    expect(output).to.equal(30);
  });

  it('XL', function () {
    var input = 'XL';
    var output = romanToInt(input);
    expect(output).to.equal(40);
  });

  it('XLVIII', function () {
    var input = 'XLVIII';
    var output = romanToInt(input);
    expect(output).to.equal(48);
  });

  it('XLIX', function () {
    var input = 'XLIX';
    var output = romanToInt(input);
    expect(output).to.equal(49);
  });

  it('L', function () {
    var input = 'L';
    var output = romanToInt(input);
    expect(output).to.equal(50);
  });

  it('LX', function () {
    var input = 'LX';
    var output = romanToInt(input);
    expect(output).to.equal(60);
  });

  it('XC', function () {
    var input = 'XC';
    var output = romanToInt(input);
    expect(output).to.equal(90);
{'fraction_non_alphanumeric': 0.2027988070658408, 'fraction_numerical': 0.021105758201422343, 'mean_word_length': 2.5708435708435706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2848183', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1650, 'n_words': 413}