🚀 benchmark

This commit is contained in:
platane
2020-07-21 18:15:41 +02:00
parent 1898ec16e4
commit e637604df1
13 changed files with 182 additions and 61 deletions

View File

@@ -1,4 +1,4 @@
import { snakeSelfCollide } from "../snake";
import { snakeSelfCollide, snakeWillSelfCollide } from "../snake";
test.each([
[[{ x: 0, y: 0 }], false],
@@ -22,3 +22,41 @@ test.each([
])("should report snake collision", (snake, collide) => {
expect(snakeSelfCollide(snake)).toBe(collide);
});
test.each([
[
[
{ x: 1, y: 7 },
{ x: 0, y: 7 },
{ x: 0, y: 8 },
{ x: 0, y: 9 },
{ x: 1, y: 9 },
],
{ x: 1, y: 7 },
true,
],
[
[
{ x: 1, y: 7 },
{ x: 0, y: 7 },
{ x: 0, y: 8 },
{ x: 0, y: 9 },
{ x: 1, y: 9 },
],
{ x: 1, y: 8 },
false,
],
[
[
{ x: 1, y: 7 },
{ x: 0, y: 7 },
{ x: 0, y: 8 },
{ x: 0, y: 9 },
{ x: 1, y: 9 },
],
{ x: 1, y: 8 },
false,
],
])("should report snake collision next", (snake, { x, y }, collide) => {
expect(snakeWillSelfCollide(snake, x, y)).toBe(collide);
});