Skip to content

Commit

Permalink
Merge pull request #877 from rvilarl/migration/tuningFractionTest
Browse files Browse the repository at this point in the history
Migration/tuning fraction test
  • Loading branch information
0xfe authored Apr 6, 2021
2 parents 1154e6c + 4b769af commit 9d22e4c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 52 deletions.
9 changes: 7 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
"files": [ "**/*.ts" ],
"extends": [
"eslint:recommended",
"prettier"
]
"prettier",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-inferrable-types": "off"
}
},
{
"files": [ "src/**/*.js" ],
Expand Down
10 changes: 10 additions & 0 deletions tests/declarations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/**
* VexFlow - Declarations to interface with ./support/qunit.js
*/

declare const global: any;

export const QUnit = global.QUnit;
export const ok = global.ok;
export const notOk = global.notOk;
export const test = global.test;
export const expect = global.expect;
export const equal = global.equal;
export const notEqual = global.notEqual;
export const deepEqual = global.deepEqual;
export const notDeepEqual = global.notDeepEqual;
export const strictEqual = global.strictEqual;
export const notStrictEqual = global.notStrictEqual;
21 changes: 12 additions & 9 deletions tests/fraction_tests.js → tests/fraction_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/

VF.Test.Fraction = (function () {
var Fraction = {
import { Fraction } from '../src/fraction';
import { QUnit, ok, test, notOk, notEqual, strictEqual, deepEqual, notDeepEqual, notStrictEqual } from './declarations';

export default (function () {
const FractionTests = {
Start: function () {
QUnit.module('Fraction');
test('Basic', VF.Test.Fraction.basic);
test('Basic', FractionTests.basic);
},

basic: function () {
var f_1_2 = new Vex.Flow.Fraction(1, 2);
const f_1_2 = new Fraction(1, 2);
ok(f_1_2.equals(0.5), 'Fraction: 1/2 equals 0.5');
ok(f_1_2.equals(new Vex.Flow.Fraction(1, 2)), 'Fraction: 1/2 equals 1/2');
ok(f_1_2.equals(new Vex.Flow.Fraction(2, 4)), 'Fraction: 1/2 equals 2/4');
ok(f_1_2.equals(new Fraction(1, 2)), 'Fraction: 1/2 equals 1/2');
ok(f_1_2.equals(new Fraction(2, 4)), 'Fraction: 1/2 equals 2/4');

notOk(f_1_2.greaterThan(1), 'Fraction: ! 1/2 > 1');
ok(f_1_2.greaterThan(0.2), 'Fraction: 1/2 > 0.2');
Expand All @@ -30,12 +33,12 @@ VF.Test.Fraction = (function () {
ok(f_1_2.lessThanEquals(0.5), 'Fraction: 1/2 <= 0.5');
notOk(f_1_2.lessThanEquals(0.4), 'Fraction: ! 1/2 <= 0.4');

var f_05 = f_1_2.copy(0.5);
const f_05 = f_1_2.copy(0.5);
strictEqual(f_05, f_1_2, 'Fraction: f_05 === f_1_2');
strictEqual(f_05.toString(), '0.5/1', 'Fraction: f_05.toString() === "0.5/1"');
strictEqual(f_05.toSimplifiedString(), '1/2', 'Fraction: f_05.toSimplifiedString() === "1/2"');

var tF_n = f_05.clone();
const tF_n = f_05.clone();
notStrictEqual(tF_n, f_05, 'Fraction: tF_n !== f_05');
notEqual(tF_n, f_05, 'Fraction: tF_n != f_05');
deepEqual(tF_n, f_05, 'tF_n deepEqual f_05');
Expand All @@ -54,5 +57,5 @@ VF.Test.Fraction = (function () {
},
};

return Fraction;
return FractionTests;
})();
51 changes: 26 additions & 25 deletions tests/music_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* VexFlow - Music API Tests
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/

import { Music } from '../src/music';
import { KeyManager } from '../src/keymanager';
import { QUnit, ok, test, expect, equal } from './declarations';

export default (function () {
var MusicTests = {
const MusicTests = {
Start: function () {
QUnit.module('MusicTests');
test('Valid Notes', MusicTests.validNotes);
Expand All @@ -25,9 +26,9 @@ export default (function () {
validNotes: function () {
expect(10);

var music = new Music();
const music = new Music();

var parts = music.getNoteParts('c');
let parts = music.getNoteParts('c');
equal(parts.root, 'c');
equal(parts.accidental, null);

Expand Down Expand Up @@ -59,9 +60,9 @@ export default (function () {
validKeys: function () {
expect(18);

var music = new Music();
const music = new Music();

var parts = music.getKeyParts('c');
let parts = music.getKeyParts('c');
equal(parts.root, 'c');
equal(parts.accidental, null);
equal(parts.type, 'M');
Expand Down Expand Up @@ -108,9 +109,9 @@ export default (function () {
noteValue: function () {
expect(3);

var music = new Music();
const music = new Music();

var note = music.getNoteValue('c');
let note = music.getNoteValue('c');
equal(note, 0);

try {
Expand All @@ -126,9 +127,9 @@ export default (function () {
intervalValue: function () {
expect(2);

var music = new Music();
const music = new Music();

var value = music.getIntervalValue('b2');
const value = music.getIntervalValue('b2');
equal(value, 1);

try {
Expand All @@ -141,9 +142,9 @@ export default (function () {
relativeNotes: function () {
expect(8);

var music = new Music();
const music = new Music();

var value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b5'));
let value = music.getRelativeNoteValue(music.getNoteValue('c'), music.getIntervalValue('b5'));
equal(value, 6);

try {
Expand Down Expand Up @@ -184,7 +185,7 @@ export default (function () {
relativeNoteNames: function () {
expect(9);

var music = new Music();
const music = new Music();
equal(music.getRelativeNoteName('c', music.getNoteValue('c')), 'c');
equal(music.getRelativeNoteName('c', music.getNoteValue('db')), 'c#');
equal(music.getRelativeNoteName('c#', music.getNoteValue('db')), 'c#');
Expand All @@ -205,7 +206,7 @@ export default (function () {
canonicalNotes: function () {
expect(3);

var music = new Music();
const music = new Music();

equal(music.getCanonicalNoteName(0), 'c');
equal(music.getCanonicalNoteName(2), 'd');
Expand All @@ -220,7 +221,7 @@ export default (function () {
canonicalIntervals: function () {
expect(3);

var music = new Music();
const music = new Music();

equal(music.getCanonicalIntervalName(0), 'unison');
equal(music.getCanonicalIntervalName(2), 'M2');
Expand All @@ -236,36 +237,36 @@ export default (function () {
expect(24);

// C Major
var music = new Music();
var manager = new KeyManager('CM');
const music = new Music();
const manager = new KeyManager('CM');

var c_major = music.getScaleTones(music.getNoteValue('c'), Music.scales.major);
var values = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
const c_major = music.getScaleTones(music.getNoteValue('c'), Music.scales.major);
let values = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];

equal(c_major.length, 7);

for (var cm = 0; cm < c_major.length; ++cm) {
for (let cm = 0; cm < c_major.length; ++cm) {
equal(music.getCanonicalNoteName(c_major[cm]), values[cm]);
}

// Dorian
var c_dorian = music.getScaleTones(music.getNoteValue('c'), Music.scales.dorian);
const c_dorian = music.getScaleTones(music.getNoteValue('c'), Music.scales.dorian);
values = ['c', 'd', 'eb', 'f', 'g', 'a', 'bb'];

var note = null;
let note = null;
equal(c_dorian.length, 7);
for (var cd = 0; cd < c_dorian.length; ++cd) {
for (let cd = 0; cd < c_dorian.length; ++cd) {
note = music.getCanonicalNoteName(c_dorian[cd]);
equal(manager.selectNote(note).note, values[cd]);
}

// Mixolydian
var c_mixolydian = music.getScaleTones(music.getNoteValue('c'), Music.scales.mixolydian);
const c_mixolydian = music.getScaleTones(music.getNoteValue('c'), Music.scales.mixolydian);
values = ['c', 'd', 'e', 'f', 'g', 'a', 'bb'];

equal(c_mixolydian.length, 7);

for (var i = 0; i < c_mixolydian.length; ++i) {
for (let i = 0; i < c_mixolydian.length; ++i) {
note = music.getCanonicalNoteName(c_mixolydian[i]);
equal(manager.selectNote(note).note, values[i]);
}
Expand All @@ -274,7 +275,7 @@ export default (function () {
scaleIntervals: function () {
expect(6);

var music = new Music();
const music = new Music();

equal(
music.getCanonicalIntervalName(music.getIntervalBetween(music.getNoteValue('c'), music.getNoteValue('d'))),
Expand Down
6 changes: 4 additions & 2 deletions tests/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import FractionTests from './fraction_tests';
import MusicTests from './music_tests';
import TuningTests from './tuning_tests';

VF.Test.run = function () {
VF.Test.Accidental.Start();
Expand All @@ -11,7 +13,7 @@ VF.Test.run = function () {
VF.Test.Dot.Start();
VF.Test.Bend.Start();
VF.Test.Formatter.Start();
VF.Test.Fraction.Start();
FractionTests.Start();
VF.Test.Clef.Start();
VF.Test.KeySignature.Start();
VF.Test.TimeSignature.Start();
Expand All @@ -29,7 +31,7 @@ VF.Test.run = function () {
VF.Test.VibratoBracket.Start();
VF.Test.Annotation.Start();
VF.Test.ChordSymbol.Start();
VF.Test.Tuning.Start();
TuningTests.Start();
MusicTests.Start();
VF.Test.KeyManager.Start();
VF.Test.Articulation.Start();
Expand Down
31 changes: 17 additions & 14 deletions tests/tuning_tests.js → tests/tuning_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/

VF.Test.Tuning = (function () {
var Tuning = {
import { Tuning } from '../src/tuning';
import { QUnit, test, equal, expect } from './declarations';

export default (function () {
const TuningTests = {
Start: function () {
QUnit.module('Tuning');
test('Standard Tuning', VF.Test.Tuning.standard);
test('Standard Banjo Tuning', VF.Test.Tuning.banjo);
test('Return note for fret', VF.Test.Tuning.noteForFret);
test('Standard Tuning', TuningTests.standard);
test('Standard Banjo Tuning', TuningTests.banjo);
test('Return note for fret', TuningTests.noteForFret);
},

checkStandard: function (tuning) {
checkStandard: function (tuning: Tuning) {
try {
tuning.getValueForString(0);
} catch (e) {
Expand All @@ -33,7 +36,7 @@ VF.Test.Tuning = (function () {
equal(tuning.getValueForString(1), 64, 'High E string');
},

checkStandardBanjo: function (tuning) {
checkStandardBanjo: function (tuning: Tuning) {
try {
tuning.getValueForString(0);
} catch (e) {
Expand All @@ -56,25 +59,25 @@ VF.Test.Tuning = (function () {
banjo: function () {
expect(7);

var tuning = new VF.Tuning();
const tuning = new Tuning();
tuning.setTuning('standardBanjo');
VF.Test.Tuning.checkStandardBanjo(tuning);
TuningTests.checkStandardBanjo(tuning);
},

standard: function () {
expect(16);

var tuning = new VF.Tuning();
VF.Test.Tuning.checkStandard(tuning);
const tuning = new Tuning();
TuningTests.checkStandard(tuning);

// Test named tuning
tuning.setTuning('standard');
VF.Test.Tuning.checkStandard(tuning);
TuningTests.checkStandard(tuning);
},

noteForFret: function () {
expect(8);
var tuning = new VF.Tuning('E/5,B/4,G/4,D/4,A/3,E/3');
const tuning = new Tuning('E/5,B/4,G/4,D/4,A/3,E/3');
try {
tuning.getNoteForFret(-1, 1);
} catch (e) {
Expand All @@ -96,5 +99,5 @@ VF.Test.Tuning = (function () {
},
};

return Tuning;
return TuningTests;
})();

0 comments on commit 9d22e4c

Please sign in to comment.