Skip to content

Commit

Permalink
test: fixed tests.js to addressed updated TicTacToe.js
Browse files Browse the repository at this point in the history
docs: also added linter badge to readme.md
  • Loading branch information
mrdcvlsc committed Jul 1, 2023
1 parent a0388f4 commit 3f38847
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# **MiniMax Tic-Tac-Toe**

![tests](https://github.com/mrdcvlsc/minimax-tic-tac-toe/actions/workflows/tests.yml/badge.svg)
![linter](https://github.com/mrdcvlsc/minimax-tic-tac-toe/actions/workflows/linter.yml/badge.svg)

A simple project showcasing my **naive implementation** of [**minimax**](https://en.wikipedia.org/wiki/Minimax#Pseudocode) algorithm for a **tic-tac-toe** web application game.

Expand Down
48 changes: 28 additions & 20 deletions tests.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { TicTacToe, NA, P1, P2 } from './public/TicTacToe.js';

const t = new TicTacToe(3);
const t = new TicTacToe({ gridLength: 3 });
let failedTests = 0;

const winners = [NA, P1, P1, P1, P1, P1, P1, P2, P2, P2, P2, P2, P2, P1, P1, P2, P2];
const winners = [NA, P1, P1, P1, P1, P1, P1, P2, P2, P2, P2, P2, P2, P1, P1, P2, P2, NA];

const winBoardStates = [
[NA, NA, NA, NA, NA, NA, NA, NA, NA],
[P1, P1, P1, NA, NA, NA, NA, NA, NA],
[NA, NA, NA, P1, P1, P1, NA, NA, NA],
[NA, NA, NA, NA, NA, NA, P1, P1, P1],
[P1, NA, NA, P1, NA, NA, P1, NA, NA],
[NA, P1, NA, NA, P1, NA, NA, P1, NA],
[NA, NA, P1, NA, NA, P1, NA, NA, P1],
[P2, P2, P2, NA, NA, NA, NA, NA, NA],
[NA, NA, NA, P2, P2, P2, NA, NA, NA],
[NA, NA, NA, NA, NA, NA, P2, P2, P2],
[P2, NA, NA, P2, NA, NA, P2, NA, NA],
[NA, P2, NA, NA, P2, NA, NA, P2, NA],
[NA, NA, P2, NA, NA, P2, NA, NA, P2],
[P1, NA, NA, NA, P1, NA, NA, NA, P1],
[NA, NA, P1, NA, P1, NA, P1, NA, NA],
[P2, NA, NA, NA, P2, NA, NA, NA, P2],
[NA, NA, P2, NA, P2, NA, P2, NA, NA],
[NA, NA, NA, NA, NA, NA, NA, NA, NA], // no winner
[P1, P1, P1, NA, NA, NA, NA, NA, NA], // row 1
[NA, NA, NA, P1, P1, P1, NA, NA, NA], // row 2
[NA, NA, NA, NA, NA, NA, P1, P1, P1], // row 3
[P1, NA, NA, P1, NA, NA, P1, NA, NA], // col 1
[NA, P1, NA, NA, P1, NA, NA, P1, NA], // col 2
[NA, NA, P1, NA, NA, P1, NA, NA, P1], // col 3
[P2, P2, P2, NA, NA, NA, NA, NA, NA], // row 1 - player2
[NA, NA, NA, P2, P2, P2, NA, NA, NA], // row 2 - player2
[NA, NA, NA, NA, NA, NA, P2, P2, P2], // row 3 - player2
[P2, NA, NA, P2, NA, NA, P2, NA, NA], // col 1 - player2
[NA, P2, NA, NA, P2, NA, NA, P2, NA], // col 2 - player2
[NA, NA, P2, NA, NA, P2, NA, NA, P2], // col 3 - player2
[P1, NA, NA, NA, P1, NA, NA, NA, P1], // diag \
[NA, NA, P1, NA, P1, NA, P1, NA, NA], // diag /
[P2, NA, NA, NA, P2, NA, NA, NA, P2], // diag \ - player2
[NA, NA, P2, NA, P2, NA, P2, NA, NA], // diag / - player2
[P2, P1, P2, P1, P2, NA, NA, P1, NA], // no winner
];

failedTests += t.testCheckWinner(winBoardStates, winners);
Expand Down Expand Up @@ -87,4 +88,11 @@ const moveBoardStates = [

failedTests += t.testGenerateMoves(moveBoardStates, correctMoves);

process.exit(failedTests);
if (failedTests > 0) {
console.log(`\nFAILED : ${failedTests}`);
} else {
console.log('\nPASSED : ALL');
}

process.exit(1);
// process.exit(failedTests);

0 comments on commit 3f38847

Please sign in to comment.