UNPKG

agentscape

Version:

Agentscape is a library for creating agent-based simulations. It provides a simple API for defining agents and their behavior, and for defining the environment in which the agents interact. Agentscape is designed to be flexible and extensible, allowing

72 lines (57 loc) 1.78 kB
import { test as base, expect } from 'vitest' import { Cell } from '.' import { CellGrid } from '../structures' interface TestFixture { grid: CellGrid<Cell> } const test = base.extend<TestFixture>({ grid: CellGrid.default(10) }) test('It should be initialized with default values', ({ grid }) => { const cell = grid.getCell([0, 0])! expect(cell.energy).toBeCloseTo(0) expect(cell.color.toHex()).toBe('#ffffff') }) test('It should calculate the distance to another cell', ({ grid }) => { const cell = grid.getCell([0, 0])! const other = grid.getCell([0, 1])! expect(cell.distanceTo(other)).toBeCloseTo(1) }) test('It should get immediate neighboring cells', ({ grid }) => { const cell = grid.getCell([5, 5])! const neighbors = cell.getNeighbors(grid) const expectedNeighbors = [ [4,5], [6,5], [5,4], [5,6], ] expect(neighbors.map(cell => cell.location)).toEqual(expectedNeighbors) }) test('It should get immediate neighboring cells and include self', ({ grid }) => { const cell = grid.getCell([5, 5])! const neighbors = cell.getNeighbors(grid, { includeSelf: true }) const expectedNeighbors = [ [4,5], [6,5], [5,4], [5,6], [5,5], ] expect(neighbors.map(cell => cell.location)).toEqual(expectedNeighbors) }) test('It should include diagonal neighboring cells', ({ grid }) => { const cell = grid.getCell([5, 5])! const neighbors = cell.getNeighbors(grid, { includeDiagonals: true }) const expectedNeighbors = [ [4,5], [6,5], [5,4], [5,6], [4,4], [4,6], [6,4], [6,6], ] expect(neighbors.map(cell => cell.location)).toEqual(expectedNeighbors) })