MeasureSizeCalculator.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 = new Vex.Flow.Formatter();
  10. let formatter: any;
  11. // Create a voice with a note
  12. let voice: Vex.Flow.Voice;
  13. let note: Vex.Flow.StaveNote;
  14. let calc: MeasureSizeCalculator;
  15. it("One note", (done: MochaDone) => {
  16. formatter = new Vex.Flow.Formatter();
  17. voice = new Vex.Flow.Voice(undefined);
  18. note = new Vex.Flow.StaveNote({ keys: ["b/4"], "duration": "1" });
  19. voice.addTickables([note]);
  20. voices = [voice];
  21. chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(22);
  22. calc = new MeasureSizeCalculator(
  23. stave, voices, <Vex.Flow.Formatter> formatter
  24. );
  25. chai.expect(calc.getBottomBorder()).to.equal(5);
  26. done();
  27. });
  28. it("Four quarter notes", (done: MochaDone) => {
  29. formatter = new Vex.Flow.Formatter();
  30. voice = new Vex.Flow.Voice(undefined);
  31. voice.addTickables([
  32. new Vex.Flow.StaveNote({ keys: ["c/4"], "duration": "q" }),
  33. new Vex.Flow.StaveNote({ keys: ["d/4"], "duration": "q" }),
  34. new Vex.Flow.StaveNote({ keys: ["e/4"], "duration": "q" }),
  35. new Vex.Flow.StaveNote({ keys: ["f/4"], "duration": "q" }),
  36. ]);
  37. voices = [voice];
  38. chai.expect(formatter.preCalculateMinTotalWidth(voices)).to.equal(64);
  39. calc = new MeasureSizeCalculator(
  40. stave, voices, <Vex.Flow.Formatter> formatter
  41. );
  42. chai.expect(calc.getWidth()).to.equal(64);
  43. chai.expect(calc.getBottomBorder()).to.equal(6);
  44. chai.expect(calc.getTopBorder()).to.equal(0);
  45. done();
  46. });
  47. });