mirror of
https://github.com/liabru/matter-js.git
synced 2025-03-14 00:38:41 -04:00
Bounds.update unit tests
This commit is contained in:
parent
127c95b6f4
commit
33e84ae148
2 changed files with 68 additions and 0 deletions
|
@ -172,6 +172,11 @@ const testVerticesAreaZeroWithoutBody = [
|
|||
{ x: 1., y: 3., index: 3, body: undefined, isInternal: false, },
|
||||
];
|
||||
|
||||
const testBounds = {
|
||||
min: { x: 100, y: 150, },
|
||||
max: { x: 200, y: 250, },
|
||||
};
|
||||
|
||||
const getTestSquare = () => {
|
||||
return _.cloneDeep(testSquare);
|
||||
}
|
||||
|
@ -210,6 +215,10 @@ const getTestVerticesAreaZeroWithoutBody = () => {
|
|||
return _.cloneDeep(testVerticesAreaZeroWithoutBody);
|
||||
};
|
||||
|
||||
const getTestBounds = () => {
|
||||
return _.cloneDeep(testBounds);
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
getTestSquare,
|
||||
|
@ -220,4 +229,5 @@ module.exports = {
|
|||
getTestVerticesSqaureWithoutBody,
|
||||
getTestVerticesNegAreaWithoutBody,
|
||||
getTestVerticesAreaZeroWithoutBody,
|
||||
getTestBounds,
|
||||
};
|
|
@ -1,8 +1,10 @@
|
|||
const {assertBounds} = require("../TestUtil");
|
||||
const {
|
||||
getTestVerticesSqaureWithoutBody,
|
||||
getTestBounds,
|
||||
} = require("../TestData");
|
||||
const Bounds = require("../../../src/geometry/Bounds");
|
||||
const Vector = require("../../../src/geometry/Vector");
|
||||
|
||||
describe('Bounds.create', () => {
|
||||
it('should be able to create bounds from valid vertices', () => {
|
||||
|
@ -27,4 +29,60 @@ describe('Bounds.create', () => {
|
|||
assertBounds(result, 0., 0., 0., 0.);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('Bounds.update', () => {
|
||||
it('should be able to update bounds with valid vertices', () => {
|
||||
// Arrange
|
||||
const bounds = getTestBounds();
|
||||
const vertices = getTestVerticesSqaureWithoutBody();
|
||||
const velocity = Vector.create(5., 6.);
|
||||
|
||||
// Act
|
||||
Bounds.update(bounds, vertices, velocity);
|
||||
|
||||
// Assert
|
||||
assertBounds(bounds, 1., 1., 8., 9.);
|
||||
});
|
||||
|
||||
it('should be able to update bounds with valid vertices and undefined velocity', () => {
|
||||
// Arrange
|
||||
const bounds = getTestBounds();
|
||||
const vertices = getTestVerticesSqaureWithoutBody();
|
||||
const velocity = undefined;
|
||||
|
||||
// Act
|
||||
Bounds.update(bounds, vertices, velocity);
|
||||
|
||||
// Assert
|
||||
assertBounds(bounds, 1., 1., 3., 3.);
|
||||
});
|
||||
|
||||
it('should not be able to update bounds with undefined vertices and undefined velocity', () => {
|
||||
// Arrange
|
||||
const bounds = getTestBounds();
|
||||
const vertices = undefined;
|
||||
const velocity = undefined;
|
||||
|
||||
// Act
|
||||
const result = () => Bounds.update(bounds, vertices, velocity);
|
||||
|
||||
// TODO: This causes a read from undefined. This should probably be fixed.
|
||||
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
|
||||
});
|
||||
|
||||
it('should not be able to update undefined bounds with valid vertices', () => {
|
||||
// Arrange
|
||||
const bounds = undefined;
|
||||
const vertices = getTestVerticesSqaureWithoutBody();
|
||||
const velocity = Vector.create(5., 6.);
|
||||
|
||||
// Act
|
||||
const result = () => Bounds.update(bounds, vertices, velocity);
|
||||
|
||||
// TODO: This causes a read from undefined. This should probably be fixed.
|
||||
expect(result).toThrow("Cannot read properties of undefined (reading 'min')");
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue