From 7ca6bcfb6cab46103f2f6d8e714c3e06b8157033 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 28 Jul 2025 14:07:40 -0400 Subject: add player tests --- player-tests.mjs | 20 ++++++++++++++++++++ player.mjs | 19 ------------------- tests.mjs | 2 ++ 3 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 player-tests.mjs diff --git a/player-tests.mjs b/player-tests.mjs new file mode 100644 index 0000000..e2ba42f --- /dev/null +++ b/player-tests.mjs @@ -0,0 +1,20 @@ +import { Note, toCents } from './scale.mjs'; + +export default function() { + const cNote = Note.fromString('C'); + console.assert(cNote.distanceTo(cNote) === 0); + const dNote = Note.fromString('D'); + console.assert(cNote.distanceTo(dNote) === 2); + const dSharpNote = Note.fromString('D♯'); + console.assert(cNote.distanceTo(dSharpNote) === 3); + + const aNote = Note.fromString('A', 'A to A'); + console.assert(toCents([aNote, 4], [aNote, 3]) === -1200); + const bNote = Note.fromString('B'); + console.assert(toCents([aNote, 4], [bNote, 4]) == 200, 'A4 to B4 is 200 cents'); + // E F F# G G# A + const eNote = Note.fromString('E'); + console.assert(toCents([aNote, 4], [eNote, 4]) === -500, 'E4 is 500 cents lower than A4'); + + console.assert(toCents([aNote, 4], [bNote, 3]) === -1000, 'A4 to B3 is 100 cents above -1200'); +} diff --git a/player.mjs b/player.mjs index 55ce64f..070a8b7 100644 --- a/player.mjs +++ b/player.mjs @@ -44,23 +44,4 @@ export default class { console.debug('Player#stop', this); this.notes.forEach(n => n.stop()); } - - test() { - const cNote = Note.fromString('C'); - console.assert(cNote.distanceTo(cNote) === 0); - const dNote = Note.fromString('D'); - console.assert(cNote.distanceTo(dNote) === 2); - const dSharpNote = Note.fromString('D♯'); - console.assert(cNote.distanceTo(dSharpNote) === 3); - - const aNote = Note.fromString('A', 'A to A'); - console.assert(toCents([aNote, 4], [aNote, 3]) === -1200); - const bNote = Note.fromString('B'); - console.assert(toCents([aNote, 4], [bNote, 4]) == 200, 'A4 to B4 is 200 cents'); - // E F F# G G# A - const eNote = Note.fromString('E'); - console.assert(toCents([aNote, 4], [eNote, 4]) === -500, 'E4 is 500 cents lower than A4'); - - console.assert(toCents([aNote, 4], [bNote, 3]) === -1000, 'A4 to B3 is 100 cents above -1200'); - } } diff --git a/tests.mjs b/tests.mjs index fc3c57c..114ddf8 100644 --- a/tests.mjs +++ b/tests.mjs @@ -1,9 +1,11 @@ import TestHarness from './test-harness.mjs'; +import playerTests from './player-tests.mjs'; import scaleTests from './scale-tests.mjs'; function init() { TestHarness.register(); TestHarness.elements.forEach(e => { + e.addTests(playerTests); e.addTests(scaleTests); e.run(); -- cgit v1.3