refactor: Переименована функция calculateCollision для лучшей семантики

This commit is contained in:
Ilia Mashkov
2026-07-19 17:00:23 +03:00
parent 8d15f3996f
commit d2cfee3ec3
6 changed files with 16 additions and 18 deletions
@@ -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);
});
});