MeasureSizeCalculator.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. MeasureSizeCalculator,
  3. } from "../../../src/MusicalScore/Calculation/MeasureSizeCalculator.ts";
  4. import Vex = require("vexflow");
  5. describe("Measure Size Calculator Tests", () => {
  6. // Initialization
  7. let stave: Vex.Flow.Stave = new Vex.Flow.Stave(0, 0, 0);
  8. let voices: Vex.Flow.Voice[];
  9. let formatter: Vex.Flow.Formatter;
  10. let voice: Vex.Flow.Voice;
  11. let note: Vex.Flow.StaveNote;
  12. let calc: MeasureSizeCalculator;
  13. it("One note", (done: MochaDone) => {
  14. formatter = new Vex.Flow.Formatter();
  15. voice = new Vex.Flow.Voice(undefined);
  16. note = new Vex.Flow.StaveNote({ keys: ["b/4"], "duration": "1" });
  17. voice.addTickables([note]);
  18. voices = [voice];
  19. chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(22);
  20. calc = new MeasureSizeCalculator(stave, voices, formatter);
  21. chai.expect(calc.getBottomBorder()).to.equal(5);
  22. done();
  23. });
  24. it("Four quarter notes", (done: MochaDone) => {
  25. formatter = new Vex.Flow.Formatter();
  26. voice = new Vex.Flow.Voice(undefined);
  27. voice.addTickables([
  28. new Vex.Flow.StaveNote({ keys: ["c/4"], "duration": "q" }),
  29. new Vex.Flow.StaveNote({ keys: ["d/4"], "duration": "q" }),
  30. new Vex.Flow.StaveNote({ keys: ["e/4"], "duration": "q" }),
  31. new Vex.Flow.StaveNote({ keys: ["f/4"], "duration": "q" }),
  32. ]);
  33. voices = [voice];
  34. chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(64);
  35. calc = new MeasureSizeCalculator(stave, voices, formatter);
  36. chai.expect(calc.getWidth()).to.equal(64);
  37. chai.expect(calc.getBottomBorder()).to.equal(6);
  38. chai.expect(calc.getTopBorder()).to.equal(0);
  39. done();
  40. });
  41. });