-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,91 @@ | ||
|
||
/* global assert */ | ||
import Board from './Board'; | ||
|
||
describe('модель', function () { | ||
describe('конструктор', function () { | ||
const arr = new Board(2, 2); | ||
it('матрица', function () { | ||
const a = new Board(0, 0); | ||
assert.deepEqual(a.matrix, [], 'not empty array'); | ||
assert.deepEqual(arr.matrix, [[false, false], [false, false]], 'должна быть матрица 2 на 2 с ложными значениями'); | ||
describe('модель', () => { | ||
const modelRows = 5; | ||
const modelColumns = 5; | ||
let model; | ||
beforeEach(() => { | ||
model = new Board(modelRows, modelColumns); | ||
}); | ||
describe('конструктор', () => { | ||
it('матрица', () => { | ||
const board = new Board(2, 2); | ||
assert.deepEqual(board.matrix, [[false, false], [false, false]], 'должна быть матрица 2 на 2 с ложными значениями'); | ||
}); | ||
it('атрибуты', () => { | ||
assert.equal(model.rows, modelRows); | ||
assert.equal(model.columns, modelColumns); | ||
}); | ||
it('атрибуты', function () { | ||
assert.equal(arr.m, 2); | ||
assert.equal(arr.n, 2); | ||
}) | ||
}); | ||
describe('методы модели', function () { | ||
let arr = new Board(2, 2); | ||
it('set cell', function () { | ||
arr.setCell(0, 0); | ||
assert.equal(arr.matrix[0][0], true, 'переключение ячейки'); | ||
arr.setCell(0, 0); | ||
assert.equal(arr.matrix[0][0], false, 'переключение ячейки'); | ||
describe('методы', () => { | ||
describe('resizeMatrix', () => { | ||
it('увеличение', () => { | ||
model.resizeMatrix(50, 40); | ||
assert.equal(model.matrix.length, 50, '50 строк матрицы'); | ||
assert.equal(model.rows, 50, '50 строк'); | ||
assert.equal(model.matrix[0].length, 40, '40 столбцов матрицы'); | ||
assert.equal(model.columns, 40, '40 столбцов'); | ||
assert.equal(model.matrix[49][39], false, 'значение ячейки'); | ||
}); | ||
it('уменьшение', () => { | ||
model.resizeMatrix(50, 40); | ||
model.resizeMatrix(10, 9); | ||
assert.equal(model.matrix.length, 10, '10 строк матрицы'); | ||
assert.equal(model.rows, 10, '10 строк'); | ||
assert.equal(model.matrix[0].length, 9, '9 столбцов матрицы'); | ||
assert.equal(model.columns, 9, '9 столбцов'); | ||
}); | ||
}); | ||
it('clear', function () { | ||
arr.setCell(0, 0); | ||
arr.setCell(1, 1); | ||
arr.clear(); | ||
assert.equal(arr.matrix[0][0], false, 'ячейки обнулились'); | ||
assert.equal(arr.matrix[1][1], false, 'ячейки обнулились'); | ||
it('clearMatrix', () => { | ||
model.toggleCell(0, 0); | ||
model.toggleCell(1, 1); | ||
model.clearMatrix(); | ||
assert.equal(model.matrix[0][0], false, 'ячейки обнулились'); | ||
assert.equal(model.matrix[1][1], false, 'ячейки обнулились'); | ||
}); | ||
arr = new Board(3, 3); | ||
it('cell', function () { | ||
arr.setCell(0, 0); | ||
arr.setCell(0, 1); | ||
assert.equal(arr.cell(1, 1), false, '2 живых соседа'); | ||
it('calculateMatrix', () => { | ||
const arr = new Board(3, 3); | ||
let flag; | ||
arr.toggleCell(0, 0); arr.toggleCell(0, 1); arr.toggleCell(1, 0); | ||
assert.deepEqual(arr.matrix, [ | ||
[true, true, false], [true, false, false], [false, false, false], | ||
]); | ||
|
||
arr.setCell(1, 0); | ||
assert.equal(arr.cell(1, 1), true, '3 живых соседа'); | ||
flag = arr.calculateMatrix(); | ||
assert.deepEqual(arr.matrix, [ | ||
[true, true, false], [true, true, false], [false, false, false], | ||
]); | ||
assert.equal(flag, false, 'матрица не повторилась'); | ||
|
||
arr.setCell(0, 2); | ||
assert.equal(arr.cell(1, 1), false, '4 живых соседа'); | ||
flag = arr.calculateMatrix(); | ||
assert.deepEqual(arr.matrix, [ | ||
[true, true, false], [true, true, false], [false, false, false], | ||
]); | ||
assert.equal(flag, true, 'матрица повторилась'); | ||
}); | ||
it('worker', function () { | ||
arr.worker(); | ||
assert.deepEqual(arr.matrix, [[true, true, false], [true, false, false], [false, false, false]],'одна итерация'); | ||
const board = new Board(3, 3); | ||
const oldBoard = board; | ||
board.worker(); | ||
assert.equal(board, oldBoard, 'если матрица не меняется, ссылка остаетя актуальной'); | ||
it('isRepeat', () => { | ||
let value = model.isRepeatMatrix(model.matrix); | ||
assert.equal(value, false, 'первая проверка'); | ||
value = model.isRepeatMatrix(model.matrix); | ||
assert.equal(value, true, 'вторая проверка'); | ||
}); | ||
describe('resize', function () { | ||
it('увеличение', function () { | ||
arr.resize(50, 40); | ||
assert.equal(arr.matrix.length, 50, '50 строк'); | ||
assert.equal(arr.m, 50, '50 строк'); | ||
assert.equal(arr.matrix[0].length, 40, '40 столбцов'); | ||
assert.equal(arr.n, 40, '40 столбцов'); | ||
assert.equal(arr.matrix[49][39], false, 'значение'); | ||
}); | ||
it('уменьшение', function () { | ||
arr.resize(10, 9); | ||
assert.equal(arr.matrix.length, 10, 'уменьшение'); | ||
assert.equal(arr.m, 10, '10 строк'); | ||
assert.equal(arr.matrix[0].length, 9, '9 столбцов'); | ||
assert.equal(arr.n, 9, '9 столбцов'); | ||
}); | ||
it('calculateCell', () => { | ||
model.toggleCell(0, 0); | ||
model.toggleCell(0, 1); | ||
assert.equal(model.calculateCell(1, 1), false, '2 живых соседа'); | ||
|
||
model.toggleCell(1, 0); | ||
assert.equal(model.calculateCell(1, 1), true, '3 живых соседа'); | ||
|
||
model.toggleCell(0, 2); | ||
assert.equal(model.calculateCell(1, 1), false, '4 живых соседа'); | ||
}); | ||
it('toggleCell', () => { | ||
model.toggleCell(0, 0); | ||
assert.equal(model.matrix[0][0], true, 'переключение ячейки'); | ||
model.toggleCell(0, 0); | ||
assert.equal(model.matrix[0][0], false, 'переключение ячейки'); | ||
}); | ||
}); | ||
}); |