Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add white-box unit tests for modules/code-builder/src/collision/utils/index.ts #358

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions modules/code-builder/src/collision/spec/checkCollision.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { checkCollision } from '../utils/index';
import { TCollisionObject } from '@/@types/collision';

describe('checkCollision', () => {
it('should return true if two circles are colliding', () => {
const objA = {
id: 'a',
x: 0,
y: 0,
width: 10,
height: 10,
};
const objB = {
id: 'b',
x: 5,
y: 5,
width: 10,
height: 10,
};

const result = checkCollision(objA, objB, {
objType: 'circle',
colThres: 0,
});

expect(result).toBe(true);
});

it('should return false if two circles are not colliding', () => {
const objA = {
id: 'a',
x: 0,
y: 0,
width: 10,
height: 10,
};
const objB = {
id: 'b',
x: 20,
y: 20,
width: 10,
height: 10,
};

const result = checkCollision(objA, objB, {
objType: 'circle',
colThres: 0,
});

expect(result).toBe(false);
});

it('should return true if two rectangles are colliding', () => {
const objA = {
id: 'a',
x: 0,
y: 0,
width: 10,
height: 10,
};
const objB = {
id: 'b',
x: 5,
y: 5,
width: 10,
height: 10,
};

const result = checkCollision(objA, objB, {
objType: 'rect',
colThres: 0,
});

expect(result).toBe(true);
});

it('should return false if two rectangles are not colliding', () => {
const objA = {
id: 'a',
x: 0,
y: 0,
width: 10,
height: 10,
};
const objB = {
id: 'b',
x: 20,
y: 20,
width: 10,
height: 10,
};

const result = checkCollision(objA, objB, {
objType: 'rect',
colThres: 0,
});

expect(result).toBe(false);
});
});

export { checkCollision };