avocado/packages/math/test/floodwalk.js
2022-03-14 15:07:47 -05:00

26 lines
688 B
JavaScript

import {expect} from 'chai';
import floodwalk from '../src/floodwalk';
describe('Floodwalk', () => {
it('can walk', () => {
const data = [
0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 1,
];
let correct = data.reduce((r, v, i) => r.concat(v ? [+i] : []), []);
expect(
floodwalk(new Set([1]), data, [1, 1, 8, 4])
.sort((l, r) => (l < r ? -1 : 1)),
).to.deep.equal(correct);
data[12] = 0;
correct = [9, 10, 11, 16, 17, 18, 19];
expect(
floodwalk(new Set([1]), data, [1, 1, 8, 4])
.sort((l, r) => (l < r ? -1 : 1)),
).to.deep.equal(correct);
});
});