Skip to content

Commit

Permalink
test: tilesInRange(1) from origin tile
Browse files Browse the repository at this point in the history
  • Loading branch information
manuartero committed Jan 9, 2023
1 parent 34a740d commit 8a5a4c8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/models/tiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { tilesInRange } from "./tiles";

describe("tilesInRange()", () => {
/**
* [ ] [X] [X]
* [ ] [X] [.] [X]
* [ ] [ ] [X] [X] [ ]
*
*/
it("returns tilesID[] in range 1 from origin tile", () => {
const got = tilesInRange("1,-2", { range: 1 });
expect(got).toEqual(["1,-3", "2,-3", "0,-2", "2,-2", "1,-1", "2,-1"]);
});
});
29 changes: 28 additions & 1 deletion src/models/tiles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/**
* ```
* [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ] [ ]
* [ ] [ ] [ ] [ ] [ ]
*
* =>
*
* [-2,-3] [-1,-3] [+0,-3] [1,-3] [2,-3]
*
* [-3,-2] [-2,-2] [-1,-2] [+0,-2] [+1,-2] [+2,-2]
*
* [-3,-1] [-2,-1] [-1,-1] [+0,-1] [+1,-1] [+2,-1] [+3,-1]
*
* [-4,+0] [-3,+0] [-2,+0] [-1,+0] [+0,+0] [+1,+0] [+2,+0] [+3,+0]
*
* [-3,+1] [-2,+1] [-1,+1] [+0,+1] [+1,+1] [+2,+1] [+3,+1]
*
* [-3,+2] [-2,+2] [-1,+2] [+0,+2] [+1,+2] [+2,+2]
*
* [-2,+3] [-1,+3] [+0,+3] [1,+3] [2,+3]
* ```
*/
export const tiles = [
// 1st row
"-2,-3",
Expand Down Expand Up @@ -75,7 +102,7 @@ export function row(n: -3 | -2 | -1 | 0 | 1 | 2 | 3): TileID[] {
return tiles.filter((id) => coordinates(id).y === n);
}

export function tilesInRange(tile: TileID, range = 1): TileID[] {
export function tilesInRange(tile: TileID, { range } = { range: 1 }): TileID[] {
const { x, y } = coordinates(tile);

// TODO use range param instead of fixed array?
Expand Down

0 comments on commit 8a5a4c8

Please sign in to comment.