Core util tests (#226)

* Error message formatting, deprecate unused functions
* Add 'test-coverage' script
* Additional test coverage for core util module
* Additional tests for core util module

by @mystery-house
This commit is contained in:
MysteryHouse 2022-10-20 03:26:28 -04:00 committed by GitHub
parent a5bf8f6732
commit 113adcc5cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 467 additions and 52 deletions

View file

@ -31,6 +31,9 @@ export const fromMidi = (n) => {
return Math.pow(2, (n - 69) / 12) * 440;
};
/**
* @deprecated does not appear to be referenced or invoked anywhere in the codebase
*/
export const getFreq = (noteOrMidi) => {
if (typeof noteOrMidi === 'number') {
return fromMidi(noteOrMidi);
@ -38,6 +41,9 @@ export const getFreq = (noteOrMidi) => {
return fromMidi(toMidi(noteOrMidi));
};
/**
* @deprecated does not appear to be referenced or invoked anywhere in the codebase
*/
export const midi2note = (n) => {
const oct = Math.floor(n / 12) - 1;
const pc = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'][n % 12];
@ -75,7 +81,7 @@ export const getFrequency = (hap) => {
} else if (typeof value === 'string' && isNote(value)) {
value = fromMidi(toMidi(hap.value));
} else if (typeof value !== 'number') {
throw new Error('not a note or frequency:' + value);
throw new Error('not a note or frequency: ' + value);
}
return value;
};