Skip to content

Commit

Permalink
Formatter Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyeh committed Aug 30, 2021
1 parent 417681d commit 978aa68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/easyscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/* eslint max-classes-per-file: "off" */

import { Note } from 'note';
import { Accidental } from './accidental';
import { Articulation } from './articulation';
import { Factory } from './factory';
Expand Down Expand Up @@ -502,7 +503,7 @@ export class EasyScore {
return this.builder.getElements().notes;
}

voice(notes: StaveNote[], options: { time?: string; options?: { softmaxFactor: number } } = {}): Voice {
voice(notes: Note[], options: { time?: string; options?: { softmaxFactor: number } } = {}): Voice {
options = { time: this.defaults.time, ...options };
return this.factory.Voice(options).addTickables(notes);
}
Expand Down
33 changes: 14 additions & 19 deletions tests/formatter_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,22 @@ const FormatterTests = {
},

buildTickContexts(): void {
function createTickable() {
return new MockTickable();
function createTickable(beat: number) {
return new MockTickable().setTicks(beat);
}

const R = Flow.RESOLUTION;
const BEAT = (1 * R) / 4;
const BEAT = (1 * Flow.RESOLUTION) / 4;

const tickables1 = [
createTickable().setTicks(BEAT).setWidth(10),
createTickable()
.setTicks(BEAT * 2)
.setWidth(20),
createTickable().setTicks(BEAT).setWidth(30),
createTickable(BEAT).setWidth(10),
createTickable(BEAT * 2).setWidth(20),
createTickable(BEAT).setWidth(30),
];

const tickables2 = [
createTickable()
.setTicks(BEAT * 2)
.setWidth(10),
createTickable().setTicks(BEAT).setWidth(20),
createTickable().setTicks(BEAT).setWidth(30),
createTickable(BEAT * 2).setWidth(10),
createTickable(BEAT).setWidth(20),
createTickable(BEAT).setWidth(30),
];

const voice1 = new Voice(Flow.TIME4_4);
Expand Down Expand Up @@ -276,7 +271,7 @@ const FormatterTests = {
b.setContext(ctx).draw();
});

ok(voice11.tickables[1].getX() > voice21.tickables[1].getX());
ok(voice11.getTickables()[1].getX() > voice21.getTickables()[1].getX());
},

unalignedNoteDurations2(options: TestOptions): void {
Expand Down Expand Up @@ -326,7 +321,7 @@ const FormatterTests = {
voice1.draw(context, stave1);
voice2.draw(context, stave2);

ok(voice1.tickables[1].getX() > voice2.tickables[1].getX());
ok(voice1.getTickables()[1].getX() > voice2.getTickables()[1].getX());
},

justifyStaveNotes(options: TestOptions): void {
Expand Down Expand Up @@ -367,7 +362,7 @@ const FormatterTests = {
const score = f.EasyScore();

let y = 10;
function justifyToWidth(width) {
function justifyToWidth(width: number) {
const stave = f.Stave({ y: y }).addTrebleGlyph();

const voice = score.voice(score.notes('d#4/2, (c4 d4)/8, d4/8, (c#4 e4 a4)/4', { stem: 'up' }));
Expand Down Expand Up @@ -453,8 +448,8 @@ const FormatterTests = {
}
beams.forEach((beam) => beam.setContext(ctx).draw());

const x = staves[0].x + staves[0].width;
const ys = staves.map((ss) => ss.y);
const x = staves[0].getX() + staves[0].getWidth();
const ys = staves.map((ss) => ss.getY());
voices = [];
staves = [];
const notes12 = score.notes('ab4/4, bb4/8, (cb5 eb5)/4[stem="down"], d5/8[stem="down"]');
Expand Down

0 comments on commit 978aa68

Please sign in to comment.