Testing and Debugging
This outline provides information on testing and debugging within the pacman-typescript
project.
Testing
The project leverages a variety of testing strategies, including:
Unit Tests:
- Located within the
tests
directory. - Utilize the
mocha
testing framework withchai
assertion library.
Integration Tests:
- Also located within the
tests
directory. - Utilize the
mocha
testing framework withchai
assertion library.
Example Unit Test (tests/game.test.js)
import { expect } from 'chai';
import Game from '../src/game';
describe('Game', () => {
it('should initialize with a default score of 0', () => {
const game = new Game();
expect(game.score).to.equal(0);
});
it('should increase the score when a pellet is eaten', () => {
const game = new Game();
game.eatPellet();
expect(game.score).to.equal(10);
});
});
Example Integration Test (tests/game.integration.test.js)
import { expect } from 'chai';
import Game from '../src/game';
import Board from '../src/board';
describe('Game Integration', () => {
it('should move the Pacman correctly', () => {
const game = new Game();
const board = new Board();
game.board = board;
game.movePacman('right');
expect(game.pacman.x).to.equal(1);
});
});
Running Tests:
- Utilize the
npm
commandnpm test
in the project’s root directory.
Debugging
Debugging Techniques:
- Leverage the browser’s developer tools (e.g., Chrome DevTools, Firefox Developer Tools) for interactive debugging, including:
- Setting breakpoints.
- Inspecting variables and objects.
- Stepping through code execution.
- Utilize the
console.log()
function for logging output to the browser’s console. - Employ debugging techniques within the
mocha
testing framework.
Example Debugging Output:
console.log('Pacman position:', game.pacman.x, game.pacman.y);