'use strict';

var Data = require('..');
var FS = require('fs');

function createSpectraData(filename, label, data) {
    var spectrum = Data.NMR.fromJcamp(
        FS.readFileSync(__dirname + filename).toString()
    );
    return spectrum;
};



describe('spectra-data test ethylvinylether/1h.jdx', function () {
    var spectrum=createSpectraData("/data/ethylvinylether/1h.jdx");

    it('getNucleus', function () {
        spectrum.getNucleus().should.equal("1H");
    });
    it('getSolventName', function () {
        spectrum.getSolventName().should.equal("DMSO");
    });
    it('getFirstX', function () {
        spectrum.getFirstX().should.equal(11.00659);
    });

    it('getLastX', function () {
        spectrum.getLastX().should.equal(-1.009276326659311);
    });

    it('getFirstY', function () {
        spectrum.getFirstY().should.equal(-119886);
    });

    it('getLastY', function () {
        spectrum.getLastY().should.equal(-109159);
    });

    it('getTitle', function () {
        spectrum.getTitle().should.equal('109-92-2');
    });

    it('Checking X array', function () {
        var x=spectrum.getXData();
        x.should.be.instanceof(Array).and.have.lengthOf(16384);
        x[0].should.equal(11.00659);
    });

    it('Checking Y array', function () {
        var y=spectrum.getYData();
        y.should.be.instanceof(Array).and.have.lengthOf(16384);
        y[0].should.equal(-119886);
    });

    it('Checking XY array', function () {
        var xy=spectrum.getXYData();
        xy.should.be.instanceof(Array).and.have.lengthOf(2);
        xy[0].should.be.instanceof(Array).and.have.lengthOf(16384);
        xy[1].should.be.instanceof(Array).and.have.lengthOf(16384);
        xy[0][0].should.equal(11.00659);
        xy[1][0].should.equal(-119886);
    });

    it('Checking if is2D is false', function () {
        spectrum.is2D().should.equal(false);
    });

    it('Check peak-picking in the new format', function () {
        var peakPicking = spectrum.nmrPeakDetection({"nH":8, realTop:true, thresholdFactor:1, clean:true,compile:true, idPrefix:"1H",format:"new"});
        //console.log(peakPicking[0]);
        peakPicking[0].signal[0].peak.length.should.equal(4);
    });

    it('getVector', function () {
        spectrum.getVector(0.0,10,4*1024).length.should.equal(4*1024);
    });

    it('updateIntegrals', function () {
        var peakPicking = spectrum.nmrPeakDetection({"nH":8, realTop:true, thresholdFactor:1,clean:true,compile:true, idPrefix:"1H",format:"new"});
        peakPicking[0].to = 6.47;
        var integral0 = peakPicking[0].integral;
        spectrum.updateIntegrals(peakPicking,{nH:8});
        peakPicking[0].integral.should.approximately(0.45,0.05);
        //console.log(peakPicking);
    });

});



@@ -2338,16 +2338,21 @@
 %0A%0A    it
+.only
 ('update
@@ -2385,35 +2385,50 @@
         var 
-peakPicking
+nH = 8;%0A        var ranges
  = spectrum.
@@ -2442,33 +2442,34 @@
 Detection(%7B%22nH%22:
-8
+nH
 , realTop:true, 
@@ -2545,35 +2545,30 @@
 %7D);%0A        
-peakPicking
+ranges
 %5B0%5D.to = 6.4
@@ -2594,27 +2594,22 @@
 gral0 = 
-peakPicking
+ranges
 %5B0%5D.inte
@@ -2651,25 +2651,21 @@
 als(
-peakPicking
+ranges
 ,%7BnH:
-8
+nH
 %7D);%0A
@@ -2668,35 +2668,30 @@
 %7D);%0A        
-peakPicking
+ranges
 %5B0%5D.integral
@@ -2716,53 +2716,32 @@
 ely(
-0.45,0.05);%0A        //console.log(peakPicking
+integral0/2,integral0/nH
 );%0A 

test SD.updateIntegrals improved