<commit_before>var assert = require('assert')
  , money  = require('../lib-cov/money');

var Money    = money.Money
  , Currency = money.Currency
  , EUR      = money.EUR
  , USD      = money.USD
  , BTC      = money.BTC;

suite('Currency tests', function() {

  suite('Construction tests', function() {

    test('new Currency: expected usage', function() {
      var c = new Currency('USD', 2);
      assert.equal(c.code, 'USD');
      assert.equal(c.centFactor, 100);
    });

    test('new Currency: invalid parameter, take 1 (1st argument not a string)', function() {
      assert.throws(function() {
        var m0 = new Currency(123, 456);
      }, /Currency: First argument is not a string/);
    });

    test('new Currency: invalid parameter, take 2 (2nd argument not a number)', function() {
      assert.throws(function() {
        var m0 = new Currency('hello', 'world');
      }, /Currency: Second argument is not a number/);
    });

  });

});

suite('Money tests', function() {

  suite('Construction tests', function() {

    test('new Money: expected usage', function() {
      var m0 = new Money(0.12345, BTC);
      assert.equal(m0.amount, 12345);
      assert.equal(m0.currency.code, 'BTC');
      assert.equal(m0.currency.centFactor, 100000);
    });
<commit_msg>Refactored and strengthened Currency unit tests<commit_after>var assert = require('assert'),
  money    = require('../lib-cov/money'),
  Money    = money.Money,
  Currency = money.Currency,
  EUR      = money.EUR,
  USD      = money.USD,
  BTC      = money.BTC;

suite('Currency tests', function() {
  suite('Constructor tests', function() {
    var testValidCallOnConstructor = function(name, decimals) {
      return function() {
        var fineCurrency = new Currency(name, decimals);
        assert.equal(fineCurrency.code, name);
        assert.equal(fineCurrency.centFactor, Math.pow(10, decimals));
      }
    }

    var testPassBadArgumentToConstructor = function(name, decimals, regExp) {
      return function() {
        assert.throws(function() {
          var badCurrency = new Currency(name, decimals);
        }, regExp);
      }
    }


    var dataProvider = [['BTC', 5], ['USD', 2], ['ESP', 0]];

    dataProvider.forEach(function(args, count) {
      test('new Currency: expected usage, take ' + count,
        testValidCallOnConstructor(args[0], args[1])
      );
    });


    dataProvider = [[undefined, 0], [null, 0], [{}, 0], [[], 0], [0, 0]];

    dataProvider.forEach(function(args, count) {
      test('new Currency: invalid first parameter, take ' + count,
        testPassBadArgumentToConstructor(
          args[0], args[1],
          /Currency: First argument is not a string/
        )
      );
    });


    dataProvider = [['USD'], ['USD', null], ['USD', {}], ['USD', []], ['USD', 'USD']];

    dataProvider.forEach(function(args, count) {
      test('new Currency: invalid second parameter, take ' + count,
        testPassBadArgumentToConstructor(
          args[0], args[1],
          /Currency: Second argument is not a number/
        )
      );
    });
  });
});

suite('Money tests', function() {

  suite('Construction tests', function() {

    test('new Money: expected usage', function() {
      var m0 = new Money(0.12345, BTC);
      assert.equal(m0.amount, 12345);
      assert.equal(m0.currency.code, 'BTC');
      assert.equal(m0.currency.centFactor, 100000);
    });

{'fraction_non_alphanumeric': 0.15829662261380323, 'fraction_numerical': 0.022026431718061675, 'mean_word_length': 2.8013392857142856, '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': '2915257', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1027, 'n_words': 259}