Files
arkanoid/src/lib/calculateCollision/calculateCollision.test.js
T

130 lines
2.7 KiB
JavaScript
Raw Normal View History

import { calculateCollision } from './calculateCollision';
describe('calculateCollision', () => {
it('Корректно обрабатывает невозможные кейсы (левая координата больше правой)', () => {
const firstObject = {
left: 0,
right: 20,
top: 0,
bottom: 20,
};
const secondObject = {
left: 10,
right: 0,
top: 0,
bottom: 10,
};
expect(calculateCollision(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(calculateCollision(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(calculateCollision(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(calculateCollision(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(calculateCollision(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(calculateCollision(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(calculateCollision(firstObject, secondObject)).toBe(true);
});
});