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:
parent
b363eb3f80
commit
127c95b6f4
2 changed files with 41 additions and 4 deletions
|
@ -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
|
||||
};
|
30
test/unit/geometry/Bounds.spec.js
Normal file
30
test/unit/geometry/Bounds.spec.js
Normal 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.);
|
||||
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue