-
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
1 parent
4d0a946
commit 27a5fc8
Showing
1 changed file
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { describe, beforeEach, test, expect } from '@jest/globals' | ||
import Cell from './cell' | ||
import Rules from './rules' | ||
|
||
describe('Cell', () => { | ||
let rules | ||
beforeEach(() => { | ||
rules = new Rules() | ||
}) | ||
describe('new ()', () => { | ||
test('should initialize a Cell', () => { | ||
var cell = new Cell(rules) | ||
expect(cell).toEqual({ | ||
rules, | ||
state: 0, | ||
age: 0, | ||
sprite: { alpha: 0 }, | ||
count: 0 | ||
}) | ||
}) | ||
}) | ||
describe('get isLiving ()', () => { | ||
test('should return {state === 1}', () => { | ||
const cell = new Cell(rules) | ||
expect(cell.isLiving).toBeFalsy() | ||
cell.state = 0 | ||
expect(cell.isLiving).toBeTruthy() | ||
}) | ||
}) | ||
describe('update ()', () => { | ||
test('should keep a cell state', () => { | ||
var cell = new Cell(rules) | ||
cell.update() | ||
expect(cell).toEqual({ | ||
state: 0, | ||
age: 0, | ||
sprite: { alpha: 0 }, | ||
count: 0, | ||
rules | ||
}) | ||
}) | ||
test('should reborn a cell', () => { | ||
var cell = new Cell(rules) | ||
cell.sprite = {} | ||
rules.b[0] = true | ||
cell.update() | ||
expect(cell).toEqual({ | ||
state: 1, | ||
age: 0, | ||
sprite: { alpha: 0.5 }, | ||
count: 0, | ||
rules | ||
}) | ||
}) | ||
test('should increment a living cell age', () => { | ||
var cell = new Cell(rules) | ||
cell.sprite = {} | ||
cell.state = 1 | ||
rules.s[0] = true | ||
cell.update() | ||
expect(cell.age).toEqual(1) | ||
}) | ||
test('should keep a dead cell age', () => { | ||
var cell = new Cell(rules) | ||
cell.sprite = {} | ||
cell.update() | ||
expect(cell.age).toEqual(0) | ||
}) | ||
test('should update the opacity at age == 5', () => { | ||
var cell = new Cell(rules) | ||
cell.state = 1 | ||
cell.sprite = {} | ||
cell.age = 4 | ||
rules.s[0] = true | ||
cell.update() | ||
expect(cell.sprite.alpha).toEqual(1) | ||
}) | ||
test('should kill a cell', () => { | ||
var cell = new Cell(rules) | ||
cell.state = 1 | ||
cell.sprite = {} | ||
var dead = new Cell(rules) | ||
dead.sprite = { alpha: 0 } | ||
cell.update() | ||
expect(cell).toEqual(dead) | ||
}) | ||
}) | ||
}) |