UNPKG

12tet

Version:

Music theory library for generating and working with chords, modes, intervals, etc.

59 lines (58 loc) 3.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const key_1 = require("../../src/key"); describe('Test getKeySignatureFromKeyNotes', () => { test('Execute getKeySignatureFromKeyNotes with no sharps or flats', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['C', 'D', 'E', 'F', 'G', 'A', 'B'])).toStrictEqual(''); }); test('Execute getKeySignatureFromKeyNotes with 2 sharps', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['D', 'E', 'F#', 'G', 'A', 'B', 'C#'])).toStrictEqual('2#'); }); test('Execute getKeySignatureFromKeyNotes with 2 flats', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['Bb', 'C', 'D', 'Eb', 'F', 'G', 'A'])).toStrictEqual('2b'); }); test('Execute getKeySignatureFromKeyNotes with 9 sharps', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['D#', 'E#', 'F##', 'G#', 'A#', 'B#', 'C##'])).toStrictEqual('9#'); }); test('Execute getKeySignatureFromKeyNotes with 9 flats', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['Bbb', 'Cb', 'Db', 'Ebb', 'Fb', 'Gb', 'Ab'])).toStrictEqual('9b'); }); test('Execute getKeySignatureFromKeyNotes with too few notes', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['B'])).toStrictEqual(TypeError(`Invalid key. Notes array ${['B']} does not have enough notes to make a valid key`)); }); test('Execute getKeySignatureFromKeyNotes with sharps and flats', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['C', 'D', 'E', 'F', 'G', 'A#', 'Bb'])).toStrictEqual(TypeError(`Invalid key. Notes array ${['C', 'D', 'E', 'F', 'G', 'A#', 'Bb']} cannot contain both sharps and flats`)); }); test('Execute getKeySignatureFromKeyNotes with 15 sharps', () => { expect((0, key_1.getKeySignatureFromKeyNotes)(['C###', 'D##', 'E##', 'F##', 'G##', 'A##', 'B##'])).toStrictEqual(TypeError(`Invalid key. Cannot have more than 14 sharps or flats`)); }); }); describe('Test getKeyTones', () => { test('Execute getKeyTones with C Ionian', () => { expect((0, key_1.getKeyTones)('C', 'Ionian')).toStrictEqual([["B#", "C", "Dbb"], ["C##", "D", "Ebb"], ["D##", "E", "Fb"], ["E#", "F", "Gbb"], ["F##", "G", "Abb"], ["G##", "A", "Bbb"], ["A##", "B", "Cb"]]); }); }); describe('Test convertKeyTonesToNotes', () => { test('Execute convertKeyTonesToNotes', () => { const keyTones = [["B#", "C", "Dbb"], ["C##", "D", "Ebb"], ["D##", "E", "Fb"], ["E#", "F", "Gbb"], ["F##", "G", "Abb"], ["G##", "A", "Bbb"], ["A##", "B", "Cb"]]; expect((0, key_1.convertDiatonicKeyTonesToNotes)('C', keyTones)).toStrictEqual(['C', 'D', 'E', 'F', 'G', 'A', 'B']); }); test('Execute convertKeyTonesToNotes with wrong tonic', () => { const keyTones = [["B#", "C", "Dbb"], ["C##", "D", "Ebb"], ["D##", "E", "Fb"], ["E#", "F", "Gbb"], ["F##", "G", "Abb"], ["G##", "A", "Bbb"], ["A##", "B", "Cb"]]; expect((0, key_1.convertDiatonicKeyTonesToNotes)('D', keyTones)).toStrictEqual(TypeError(`The first key tone ${["B#", "C", "Dbb"]} does not include the tonic note D`)); }); }); describe('Test adjustNote', () => { test('Execute adjustNote with natural note and a sharp', () => { expect((0, key_1.adjustNote)('C', '#')).toStrictEqual('C#'); }); test('Execute adjustNote with sharp note and a sharp', () => { expect((0, key_1.adjustNote)('C#', '#')).toStrictEqual('D'); }); test('Execute adjustNote with natural note and a flat', () => { expect((0, key_1.adjustNote)('D', 'b')).toStrictEqual('Db'); }); test('Execute adjustNote with flat note and a flat', () => { expect((0, key_1.adjustNote)('Db', 'b')).toStrictEqual('C'); }); });