import assert from 'assert';

import {PLAYER_1, PLAYER_2, Game} from './game.js';


describe('Game', () => {

    let game;
    beforeEach(() => {
        game = new Game();
    });

    describe('#checkRowWinner()', () => {

        it('returns PLAYER1 if row is all 1', () => {
            assert.equal(game.checkRowWinner([PLAYER_1, PLAYER_1, PLAYER_1]), PLAYER_1);
        });

        it('returns PLAYER2 if row is all 2', () => {
            assert.equal(game.checkRowWinner([PLAYER_2, PLAYER_2, PLAYER_2]), PLAYER_2);
        });

        it('returns null if row is mixed', () => {
            assert.equal(game.checkRowWinner([PLAYER_1, PLAYER_2, PLAYER_1]), null);
        });

        it('returns null if row is incomplete', () => {
            assert.equal(game.checkRowWinner([PLAYER_1, null, PLAYER_1]), null);
        });

    });

    describe('#checkWinner()', () => {
        it('returns null if board is empty', () => {
            game.board = [
                [null, null, null],
                [null, null, null],
                [null, null, null]
            ];
            assert.equal(game.checkWinner(), null);
        });
        it('returns winner if row is filled', () => {
            game.board = [
                [PLAYER_1, PLAYER_1, PLAYER_1],
                [null, null, null],
                [null, null, null]
            ];
            assert.equal(game.checkWinner(), PLAYER_1);
        });
        it('returns winner if column is filled', () => {
            game.board = [
                [PLAYER_1, null, null],
                [PLAYER_1, null, null],
                [PLAYER_1, null, null]
            ];
            assert.equal(game.checkWinner(), PLAYER_1);
        });

        it('returns winner if first diagonal is filled', () => {
            game.board = [
                [PLAYER_1, null, null],
                [null, PLAYER_1, null],
                [null, null, PLAYER_1]
            ];
            assert.equal(game.checkWinner(), PLAYER_1);
        });

        it('returns winner if second diagonal is filled', () => {
            game.board = [
                [null, null, PLAYER_1],
                [null, PLAYER_1, null],
                [PLAYER_1, null, null]
            ];
            assert.equal(game.checkWinner(), PLAYER_1);
        });

    });


    describe('#isGameEnded()', () => {
        it('returns true if board is full', () => {
            game.board = [
                [PLAYER_1, PLAYER_2, PLAYER_1],
                [PLAYER_2, PLAYER_1, PLAYER_2],
                [PLAYER_2, PLAYER_1, PLAYER_1]
            ];
            assert.equal(game.isGameEnded(), true);
        });
        it('returns false if board is not full', () => {
            game.board = [
                [PLAYER_1, PLAYER_2, PLAYER_1],
                [null, PLAYER_2, PLAYER_2],
                [PLAYER_1, PLAYER_1, PLAYER_2]
            ];
            assert.equal(game.isGameEnded(), false);
        });
    });

});

@@ -192,27 +192,28 @@
 ribe('#check
-Row
+Line
 Winner()', (
@@ -301,35 +301,36 @@
 equal(game.check
-Row
+Line
 Winner(%5BPLAYER_1
@@ -458,35 +458,36 @@
 equal(game.check
-Row
+Line
 Winner(%5BPLAYER_2
@@ -612,35 +612,36 @@
 equal(game.check
-Row
+Line
 Winner(%5BPLAYER_1
@@ -779,11 +779,12 @@
 heck
-Row
+Line
 Winn

Fix unit tests