diff --git a/src/Chromatogram.js b/src/Chromatogram.js index 965c533..f75f1c6 100644 --- a/src/Chromatogram.js +++ b/src/Chromatogram.js @@ -40,6 +40,18 @@ class Chromatogram { return this.series[name]; } + /** + * Delete a serie + * @param {string} name - Name of the serie + */ + deleteSerieByName(name) { + if (!this.findSerieByName(name)) { + throw new Error(`a serie with name ${name} doesn't exists`); + } else { + delete this.series[name]; + } + } + /** * Add a new serie * @param {object} serie - Object with an array of data, dimensions of the elements in the array and name of the serie diff --git a/test/chromatogram.js b/test/chromatogram.js index 52afa1c..7f5c0d0 100644 --- a/test/chromatogram.js +++ b/test/chromatogram.js @@ -21,8 +21,23 @@ test('addSerie errors', t => { t.throws(() => chrom.addSerie({dimension: 1, name: 'a'}), 'serie must have a data array'); }); -test('addSerie errors', t => { +test('get first and last time', t => { let chrom = new Chromatogram([1, 2, 3]); t.is(chrom.getFirstTime(), 1); t.is(chrom.getLastTime(), 3); }); + +test('deleteSerieByName', t => { + let chrom = new Chromatogram({ + times: [1, 2], + series: [{ + name: 'tic', + dimension: 1, + data: [1, 2] + }] + }); + t.throws(() => chrom.deleteSerieByName('ms'), 'a serie with name ms doesn\'t exists'); + + chrom.deleteSerieByName('tic'); + t.is(chrom.findSerieByName('tic'), undefined); +});