Skip to content

Commit

Permalink
feat(chromatogram): add deleteSerieByName
Browse files Browse the repository at this point in the history
closes #17
  • Loading branch information
maasencioh committed Mar 10, 2017
1 parent 2210735 commit 2e1f6e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Chromatogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion test/chromatogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 2e1f6e6

Please sign in to comment.