From a638f9505f3bc5937307f3f68da3ff7437e563e7 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 16 Apr 2022 21:34:19 +0200 Subject: [PATCH] test fromMidi + getFrequency --- packages/core/test/util.test.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/core/test/util.test.mjs b/packages/core/test/util.test.mjs index 5e8c906e..bf402793 100644 --- a/packages/core/test/util.test.mjs +++ b/packages/core/test/util.test.mjs @@ -1,5 +1,6 @@ import { strict as assert } from 'assert'; -import { isNote, tokenizeNote, toMidi, mod, compose } from '../util.mjs'; +import { pure } from '../pattern.mjs'; +import { isNote, tokenizeNote, toMidi, fromMidi, mod, compose, getFrequency } from '../util.mjs'; describe('isNote', () => { it('should recognize notes without accidentals', () => { @@ -64,6 +65,21 @@ describe('toMidi', () => { assert.equal(toMidi('C##3'), 50); }); }); +describe('fromMidi', () => { + it('should turn midi into frequency', () => { + assert.equal(fromMidi(69), 440); + assert.equal(fromMidi(57), 220); + }); +}); +describe('getFrequency', () => { + it('should turn midi into frequency', () => { + const happify = (val, context = {}) => pure(val).firstCycle()[0].setContext(context); + assert.equal(getFrequency(happify('a4')), 440); + assert.equal(getFrequency(happify('a3')), 220); + assert.equal(getFrequency(happify(440, { type: 'frequency' })), 440); // TODO: migrate when values are objects.. + assert.equal(getFrequency(happify(432, { type: 'frequency' })), 432); + }); +}); describe('mod', () => { it('should work like regular modulo with positive numbers', () => {