refactor: Переименована функция calculateCollision для лучшей семантики
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import { calculateAABBCollision } from './calculateAABBCollision';
|
||||
|
||||
describe('calculateAABBCollision', () => {
|
||||
it('Корректно обрабатывает невозможные кейсы (левая координата больше правой)', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 10,
|
||||
right: 0,
|
||||
top: 0,
|
||||
bottom: 10,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBeNull();
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает неверный формат данных', () => {
|
||||
const firstObject = {
|
||||
left: 'wrong',
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 0,
|
||||
right: 10,
|
||||
top: 0,
|
||||
bottom: 10,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBeNull();
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает отсутствие пересечения по X', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 25,
|
||||
right: 30,
|
||||
top: 0,
|
||||
bottom: 10,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBe(false);
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает отсутствие пересечения по Y', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 0,
|
||||
right: 30,
|
||||
top: 25,
|
||||
bottom: 30,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBe(false);
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает отсутствие пересечения по X и Y', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 25,
|
||||
right: 30,
|
||||
top: 25,
|
||||
bottom: 30,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBe(false);
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает пересечение', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 10,
|
||||
right: 30,
|
||||
top: 10,
|
||||
bottom: 30,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBe(true);
|
||||
});
|
||||
|
||||
it('Корректно обрабатывает вхождение', () => {
|
||||
const firstObject = {
|
||||
left: 0,
|
||||
right: 20,
|
||||
top: 0,
|
||||
bottom: 20,
|
||||
};
|
||||
|
||||
const secondObject = {
|
||||
left: 10,
|
||||
right: 15,
|
||||
top: 10,
|
||||
bottom: 15,
|
||||
};
|
||||
|
||||
expect(calculateAABBCollision(firstObject, secondObject)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user