11import * as fs from "fs" ;
22import * as path from "path" ;
3+ import { it , expect } from "bun:test" ;
34import { AnimationOptions , createGif } from ".." ;
45import * as grids from "@snk/types/__fixtures__/grid" ;
56import { snake3 as snake } from "@snk/types/__fixtures__/snake" ;
67import { createSnakeFromCells , nextSnake } from "@snk/types/snake" ;
78import { getBestRoute } from "@snk/solver/getBestRoute" ;
89import type { Options as DrawOptions } from "@snk/draw/drawWorld" ;
910
10- jest . setTimeout ( 20 * 1000 ) ;
11-
1211const upscale = 1 ;
1312const drawOptions : DrawOptions = {
1413 sizeDotBorderRadius : 2 * upscale ,
@@ -35,10 +34,46 @@ for (const key of [
3534 "small" ,
3635 "smallPacked" ,
3736] as const )
38- it ( `should generate ${ key } gif` , async ( ) => {
39- const grid = grids [ key ] ;
37+ it (
38+ `should generate ${ key } gif` ,
39+ async ( ) => {
40+ const grid = grids [ key ] ;
41+
42+ const chain = [ snake , ...getBestRoute ( grid , snake ) ! ] ;
43+
44+ const gif = await createGif (
45+ grid ,
46+ null ,
47+ chain ,
48+ drawOptions ,
49+ animationOptions
50+ ) ;
51+
52+ expect ( gif ) . toBeDefined ( ) ;
53+
54+ fs . writeFileSync ( path . resolve ( dir , key + ".gif" ) , gif ) ;
55+ } ,
56+ { timeout : 20 * 1000 }
57+ ) ;
58+
59+ it (
60+ `should generate swipper` ,
61+ async ( ) => {
62+ const grid = grids . smallFull ;
63+ let snk = createSnakeFromCells (
64+ Array . from ( { length : 6 } , ( _ , i ) => ( { x : i , y : - 1 } ) )
65+ ) ;
4066
41- const chain = [ snake , ...getBestRoute ( grid , snake ) ! ] ;
67+ const chain = [ snk ] ;
68+ for ( let y = - 1 ; y < grid . height ; y ++ ) {
69+ snk = nextSnake ( snk , 0 , 1 ) ;
70+ chain . push ( snk ) ;
71+
72+ for ( let x = grid . width - 1 ; x -- ; ) {
73+ snk = nextSnake ( snk , ( y + 100 ) % 2 ? 1 : - 1 , 0 ) ;
74+ chain . push ( snk ) ;
75+ }
76+ }
4277
4378 const gif = await createGif (
4479 grid ,
@@ -50,29 +85,7 @@ for (const key of [
5085
5186 expect ( gif ) . toBeDefined ( ) ;
5287
53- fs . writeFileSync ( path . resolve ( dir , key + ".gif" ) , gif ) ;
54- } ) ;
55-
56- it ( `should generate swipper` , async ( ) => {
57- const grid = grids . smallFull ;
58- let snk = createSnakeFromCells (
59- Array . from ( { length : 6 } , ( _ , i ) => ( { x : i , y : - 1 } ) )
60- ) ;
61-
62- const chain = [ snk ] ;
63- for ( let y = - 1 ; y < grid . height ; y ++ ) {
64- snk = nextSnake ( snk , 0 , 1 ) ;
65- chain . push ( snk ) ;
66-
67- for ( let x = grid . width - 1 ; x -- ; ) {
68- snk = nextSnake ( snk , ( y + 100 ) % 2 ? 1 : - 1 , 0 ) ;
69- chain . push ( snk ) ;
70- }
71- }
72-
73- const gif = await createGif ( grid , null , chain , drawOptions , animationOptions ) ;
74-
75- expect ( gif ) . toBeDefined ( ) ;
76-
77- fs . writeFileSync ( path . resolve ( dir , "swipper.gif" ) , gif ) ;
78- } ) ;
88+ fs . writeFileSync ( path . resolve ( dir , "swipper.gif" ) , gif ) ;
89+ } ,
90+ { timeout : 20 * 1000 }
91+ ) ;
0 commit comments