Outlook_Addin_LLM/node_modules/@fluentui/utilities/lib-amd/math.test.js

177 lines
7.5 KiB
JavaScript

define(["require", "exports", "./math"], function (require, exports, math_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
describe('math', function () {
describe('#fitContentToBounds', function () {
describe('with contain', function () {
it('shrinks to fit horizontal', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 400,
height: 300,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'contain',
})).toEqual({
width: 200,
height: 150,
});
});
it('shrinks to fit vertical', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 300,
height: 400,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'contain',
})).toEqual({
width: 150,
height: 200,
});
});
it('does not expand by default', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 100,
height: 75,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'contain',
})).toEqual({
width: 100,
height: 75,
});
});
it('expands if permitted', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 100,
height: 75,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'contain',
maxScale: 2,
})).toEqual({
width: 200,
height: 150,
});
});
});
describe('with cover', function () {
it('shrinks to fit horizontal', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 600,
height: 400,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'cover',
})).toEqual({
width: 300,
height: 200,
});
});
it('shrinks to fit vertical', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 400,
height: 600,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'cover',
})).toEqual({
width: 200,
height: 300,
});
});
it('does not expand by default', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 100,
height: 50,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'cover',
})).toEqual({
width: 100,
height: 50,
});
});
it('expands if permitted', function () {
expect((0, math_1.fitContentToBounds)({
contentSize: {
width: 100,
height: 50,
},
boundsSize: {
width: 200,
height: 200,
},
mode: 'cover',
maxScale: 4,
})).toEqual({
width: 400,
height: 200,
});
});
});
});
describe('#calculatePrecision', function () {
it('caluclatePrecision should work as intended', function () {
expect((0, math_1.calculatePrecision)(0)).toEqual(0);
expect((0, math_1.calculatePrecision)(1)).toEqual(0);
expect((0, math_1.calculatePrecision)('1')).toEqual(0);
expect((0, math_1.calculatePrecision)(200)).toEqual(-2);
expect((0, math_1.calculatePrecision)(32100012300000)).toEqual(-5);
expect((0, math_1.calculatePrecision)(231.0)).toEqual(0);
expect((0, math_1.calculatePrecision)('231.00')).toEqual(2);
expect((0, math_1.calculatePrecision)(321.00002)).toEqual(5);
expect((0, math_1.calculatePrecision)('321.00002')).toEqual(5);
expect((0, math_1.calculatePrecision)(0.002)).toEqual(3);
expect((0, math_1.calculatePrecision)('.002')).toEqual(3);
});
});
describe('#precisionRound', function () {
it('precisionRound should work as intended', function () {
expect((0, math_1.precisionRound)(1234, 0)).toEqual(1234);
expect((0, math_1.precisionRound)(1234, -1)).toEqual(1230);
expect((0, math_1.precisionRound)(1234, -3)).toEqual(1000);
expect((0, math_1.precisionRound)(1234.5678, 0)).toEqual(1235);
expect((0, math_1.precisionRound)(1234.5678, 1)).toEqual(1234.6);
expect((0, math_1.precisionRound)(1234.5678, 5)).toEqual(1234.5678);
expect((0, math_1.precisionRound)(1234.555, 2)).toEqual(1234.56);
expect((0, math_1.precisionRound)(1234.554, 2)).toEqual(1234.55);
expect((0, math_1.precisionRound)(1250, -2)).toEqual(1300);
expect((0, math_1.precisionRound)(1249, -2)).toEqual(1200);
// Different bases
expect((0, math_1.precisionRound)(1234.5, -2, 2)).toEqual(1236);
expect((0, math_1.precisionRound)(1234.5, -2, 16)).toEqual(1280);
expect((0, math_1.precisionRound)(1234.5, -2, 8)).toEqual(1216);
expect((0, math_1.precisionRound)(1234.5, -2, 7)).toEqual(1225);
});
});
});
});
//# sourceMappingURL=math.test.js.map