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

Vertices.inertia unit tests

This commit is contained in:
gsenden 2024-05-17 22:03:54 +02:00
parent 14b036a5d7
commit dd015b3e0a

View file

@ -381,5 +381,63 @@ describe('Vertices.mean', () => {
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
});
});
describe('Vertices.inertia', () => {
it('should be able to get the inertia of the valid vertices', () => {
// Arrange
const vertices = testVerticesSqaureWithoutBody;
const mass = 37.3;
// Act
const result = Vertices.inertia(vertices, mass);
// Assert
assertFloat(result, 211.36666666666665);
});
it('should be able to get the inertia of the valid vertices with negative mass', () => {
// Arrange
const vertices = testVerticesSqaureWithoutBody;
const mass = -37.3;
// Act
const result = Vertices.inertia(vertices, mass);
// Assert
assertFloat(result, -211.36666666666665);
});
it('should not be able to get the inertia of the valid vertices with undefined mass', () => {
// Arrange
const vertices = testVerticesSqaureWithoutBody;
const mass = undefined;
// Act
const result = Vertices.inertia(vertices, mass);
// Assert
// TODO: This causes the result to be NaN. This probaby should be fixed.
assertFloat(result, NaN);
});
it('should not be able to get the inertia of undefined vertices', () => {
// Arrange
const vertices = undefined;
const mass = 37.3;
// Act
const result = () => Vertices.inertia(vertices);
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
});
});