0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-03-14 00:38:41 -04:00

Bounds.create unit tests

This commit is contained in:
gsenden 2024-05-20 11:54:22 +02:00
parent b363eb3f80
commit 127c95b6f4
2 changed files with 41 additions and 4 deletions

View file

@ -1,12 +1,19 @@
const assertFloat = (result, expected) => {
expect(Math.round(result*100000)).toEqual(Math.round(expected*100000))
expect(Math.round(result * 100000)).toEqual(Math.round(expected * 100000));
}
const assertXY = (result, expectedX, expectedY) => {
assertFloat(result.x, expectedX)
assertFloat(result.y, expectedY)
assertFloat(result.x, expectedX);
assertFloat(result.y, expectedY);
}
const assertBounds = (result, expectedMinX, expectedMinY, expectedMaxX, expectedMaxY) => {
assertFloat(result.min.x, expectedMinX);
assertFloat(result.min.y, expectedMinY);
assertFloat(result.max.x, expectedMaxX);
assertFloat(result.max.y, expectedMaxY);
}
module.exports = {
assertFloat, assertXY
assertFloat, assertXY, assertBounds
};

View file

@ -0,0 +1,30 @@
const {assertBounds} = require("../TestUtil");
const {
getTestVerticesSqaureWithoutBody,
} = require("../TestData");
const Bounds = require("../../../src/geometry/Bounds");
describe('Bounds.create', () => {
it('should be able to create bounds from valid vertices', () => {
// Arrange
const vertices = getTestVerticesSqaureWithoutBody();
// Act
const result = Bounds.create(vertices);
// Assert
assertBounds(result, 1., 1., 3., 3.);
});
it('should be able to create bounds from undefined vertices', () => {
// Arrange
const vertices = undefined;
// Act
const result = Bounds.create(vertices);
// Assert
assertBounds(result, 0., 0., 0., 0.);
});
});