Skip to content

Брагин Егор#18

Open
eoL95 wants to merge 3 commits intourfu-2016:gh-pagesfrom
eoL95:gh-pages
Open

Брагин Егор#18
eoL95 wants to merge 3 commits intourfu-2016:gh-pagesfrom
eoL95:gh-pages

Conversation

@eoL95
Copy link
Copy Markdown

@eoL95 eoL95 commented May 10, 2017

Copy link
Copy Markdown
Collaborator

@VasiliiKuznecov VasiliiKuznecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно сделать тесты независимыми

Comment thread index.js
gameBoardElement.addEventListener('click', function (event) {
move(event.target.id);
if (checkWin()) {
document.querySelector('.game-victory').style.display = 'block';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сделать через навешивание класса, у которого будет соотвествующее свойство

Comment thread index.js
}

function printBoard() {
while (gameBoardElement.firstChild) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно, например, сделать gameBoardElement.innerHtml = ''

Comment thread tests/index-test.js

it('should initialize a game field', function () {
var gameCells = document.getElementsByClassName('game-cell');
chai.assert.equal(gameCells.length, 16);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно еще проверить, что числа разные и от 1 до 15

Comment thread tests/index-test.js
});

it('should move cell up', function () {
var gameBoardCopy = gameBoard.slice();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лезть в переменную, используемую в код плохо (если хотим поменять название, то надо менять и в тестах)
да и вообще, тесты не должны знать о внутренней логике кода

Comment thread tests/index-test.js
gameBoardCopy[4] = 0;
var cell = document.getElementById('4');
cell.click();
chai.assert.deepEqual(gameBoardCopy, gameBoard);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мы не это должны проверять, не то, что в памяти поменялось
в памяти то может и поменялась, но что отображается в интерфейсе при этом?
мы должны взять пустую ячейку, проверить, что она заполнилась правильным числом
должны взять ячейку, которую кликнули, проверить, что она стала пустой

Comment thread tests/index-test.js
cell.click();
chai.assert.deepEqual(gameBoardCopy, gameBoard);
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

еще нужна проверка на то, что если мы кликнем по ячейке далеко от пустой, ничего не произойдет

Comment thread tests/index-test.js
});

it('should move cell down', function () {
var gameBoardCopy = gameBoard.slice();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у тебя тесты сейчас зависят друг от друга, а надо чтобы были независимы, чтобы можно было отдельно запустить любой
поэтому в начале каждого теста надо создавать поле (можно создавать его с помощью массива значений, чтобы проверить конкретный случай)

Comment thread tests/index-test.js
});

it('should take message if player win', function () {
gameBoard = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 15];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

опять лезем во внутренности кода игры, не надо так делать, надо инициализировать поле заранее подготовленными числами

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants