'use strict';

var should = require('chai').should();
var bitcore = require('..');
var Unit = bitcore.Unit;

describe('Unit', function() {

  it('should create an instance', function() {
    var unit = new Unit(1.2, "BTC");
    should.exist(unit);
  });

  it('should have property accesors', function() {
    var unit = new Unit(1.2, "BTC");
    should.exist(unit.BTC);
    should.exist(unit.mBTC);
    should.exist(unit.bits);
    should.exist(unit.satoshis);
  });

  it('should have constructor helpers', function() {
    var unit;

    unit = Unit.fromBTC(1.00001);
    unit.BTC.should.equal(1.00001);

    unit = Unit.fromMilis(1.00001);
    unit.mBTC.should.equal(1.00001);

    unit = Unit.fromBits(100);
    unit.bits.should.equal(100);

    unit = Unit.fromSatoshis(8999);
    unit.satoshis.should.equal(8999);
  });

  it('should convert to satoshis correctly', function() {
    var unit;

    unit = Unit.fromBTC(1.3);
    unit.mBTC.should.equal(1300);
    unit.bits.should.equal(1300000);
    unit.satoshis.should.equal(130000000);

    unit = Unit.fromMilis(1.3);
    unit.BTC.should.equal(0.0013);
    unit.bits.should.equal(1300);
    unit.satoshis.should.equal(130000);

    unit = Unit.fromBits(1.3);
    unit.BTC.should.equal(0.0000013);
    unit.mBTC.should.equal(0.0013);
    unit.satoshis.should.equal(130);

    unit = Unit.fromSatoshis(3);
    unit.BTC.should.equal(0.00000003);
    unit.mBTC.should.equal(0.00003);
    unit.bits.should.equal(0.03);
  });

  it('should take in count floating point problems', function() {
    var unit = Unit.fromBTC(0.00000003);
    unit.mBTC.should.equal(0.00003);
    unit.bits.should.equal(0.03);
    unit.satoshis.should.equal(3);
  });

  it('should expose unit codes', function() {
    should.exist(Unit.BTC);
    Unit.BTC.should.equal('BTC');

    should.exist(Unit.mBTC);
    Unit.mBTC.should.equal('mBTC');

    should.exist(Unit.bits);
    Unit.bits.should.equal('bits');

    should.exist(Unit.satoshis);
    Unit.satoshis.should.equal('satoshis');
  });

  it('should expose shorthand conversion methods', function() {
    var unit = new Unit(1.3, 'BTC');
    unit.toBTC().should.equal(unit.BTC);
    unit.toMilis().should.equal(unit.mBTC);
    unit.toBits().should.equal(unit.bits);
    unit.toSatoshis().should.equal(unit.satoshis);
  });

  it('should expose a general conversion method', function() {
    var unit = new Unit(1.3, 'BTC');
    unit.to(Unit.BTC).should.equal(unit.BTC);
    unit.to(Unit.mBTC).should.equal(unit.mBTC);
    unit.to(Unit.bits).should.equal(unit.bits);
    unit.to(Unit.satoshis).should.equal(unit.satoshis);
  });

  it('should have a toString method', function() {
    var unit = new Unit(1.3, 'BTC');
    should.exist(unit.toString);
    unit.toString().should.be.a('string');
  });

  it('should have an inspect method', function() {
    var unit = new Unit(1.3, 'BTC');
    should.exist(unit.inspect);
    unit.inspect().should.be.a('string');
  });

});

@@ -180,32 +180,43 @@
 ion() %7B%0A    var 
+unit;%0A%0A    
 unit = new Unit(
@@ -212,37 +212,91 @@
 = new Unit(1.2, 
-%22BTC%22
+'BTC');%0A    should.exist(unit);%0A%0A    unit = Unit(1.2, 'BTC'
 );%0A    should.ex
@@ -397,13 +397,13 @@
 .2, 
-%22BTC%22
+'BTC'
 );%0A 
@@ -483,24 +483,24 @@
 unit.bits);%0A
-
     should.e
@@ -519,32 +519,397 @@
 toshis);%0A  %7D);%0A%0A
+  it('should allow amount as string', function() %7B%0A    var unit;%0A%0A    unit = Unit.fromBTC('1.00001');%0A    unit.BTC.should.equal(1.00001);%0A%0A    unit = Unit.fromMilis('1.00001');%0A    unit.mBTC.should.equal(1.00001);%0A%0A    unit = Unit.fromBits('100');%0A    unit.bits.should.equal(100);%0A%0A    unit = Unit.fromSatoshis('8999');%0A    unit.satoshis.should.equal(8999);%0A  %7D);%0A%0A
   it('should hav

Add new test for string values