satie
Version:
A sheet music renderer for the web
109 lines (108 loc) • 4.28 kB
JavaScript
/**
* This file is part of Satie music engraver <https://github.com/jnetterf/satie>.
* Copyright (C) Joshua Netterfield <joshua.ca> 2015 - present.
*
* Satie is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Satie is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Satie. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
/**
* @file part of Satie test suite
*/
var lodash_1 = require("lodash");
var chai_1 = require("chai");
var private_combinedLayout_1 = require("../private_combinedLayout");
var document_1 = require("../document");
var etestutil_1 = require("./etestutil");
describe("[private/combinedLayout.ts]", function () {
describe("merge", function () {
it("handles multiple segments", function () {
var layout1 = lodash_1.times(5, function (idx) { return etestutil_1.createFakeLayout(idx, 0, true); });
var layout2 = lodash_1.times(5, function (idx) { return etestutil_1.createFakeLayout(idx, idx ? 2 : 0, true); });
var combinedLayout = [];
combinedLayout = lodash_1.reduce([layout1, layout2], private_combinedLayout_1.mergeSegmentsInPlace, combinedLayout);
combinedLayout = lodash_1.reduce([layout1, layout2], private_combinedLayout_1.mergeSegmentsInPlace, combinedLayout);
chai_1.expect(combinedLayout).to.deep.equal([
{
renderClass: document_1.Type.Attributes,
x: 0,
division: 0
},
{
renderClass: document_1.Type.Attributes,
x: 100,
division: 4
},
{
renderClass: document_1.Type.Attributes,
x: 100 + 10 * Math.log(3) / Math.log(2),
division: 6
},
{
renderClass: document_1.Type.Attributes,
x: 200,
division: 8
},
{
renderClass: document_1.Type.Attributes,
x: 200 + 10 * Math.log(3) / Math.log(2),
division: 10
},
{
renderClass: document_1.Type.Attributes,
x: 300,
division: 12
},
{
renderClass: document_1.Type.Attributes,
x: 300 + 10 * Math.log(3) / Math.log(2),
division: 14
},
{
renderClass: document_1.Type.Attributes,
x: 400,
division: 16
},
{
renderClass: document_1.Type.Attributes,
x: 400 + 10 * Math.log(3) / Math.log(2),
division: 18
},
]);
chai_1.expect(layout1).to.have.length(9);
chai_1.expect(layout2).to.have.length(9);
chai_1.expect(layout1.slice(0, 3)).to.be.deep.equal([
{
boundingBoxes: [],
division: 0,
renderClass: document_1.Type.Attributes,
model: {},
x: 0
},
{
boundingBoxes: [],
division: 4,
renderClass: document_1.Type.Attributes,
model: {},
x: 100
},
{
division: 6,
renderClass: document_1.Type.Attributes,
model: null,
x: 100 + 10 * Math.log(3) / Math.log(2)
}
]);
});
});
});