Skip to content

Commit

Permalink
tuning_tests & fractions_tests migrated
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Apr 5, 2021
1 parent 1c028fc commit 9e98425
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
30 changes: 21 additions & 9 deletions tests/fraction_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/

VF.Test.Fraction = (function () {
var Fraction = {
declare const QUnit: any;
declare const ok: any;
declare const test: any;
declare const notOk: any;
declare const notEqual: any;
declare const strictEqual: any;
declare const notStrictEqual: any;
declare const deepEqual: any;
declare const notDeepEqual: any;

import { Fraction } from '../src/fraction';

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 +42,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 +66,5 @@ VF.Test.Fraction = (function () {
},
};

return Fraction;
return FractionTests;
})();
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
35 changes: 21 additions & 14 deletions tests/tuning_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
* Copyright Mohit Muthanna 2010 <mohit@muthanna.com>
*/

VF.Test.Tuning = (function () {
var Tuning = {
declare const QUnit: any;
declare const test: any;
declare const equal: any;
declare const expect: any;

import { Tuning } from '../src/tuning';

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 +40,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 +63,25 @@ VF.Test.Tuning = (function () {
banjo: function () {
expect(7);

var tuning = new VF.Tuning();
let 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);
let 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');
let 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 +103,5 @@ VF.Test.Tuning = (function () {
},
};

return Tuning;
return TuningTests;
})();

0 comments on commit 9e98425

Please sign in to comment.