From 95605bfd0be6eac035049450860d978bc6f6a25a Mon Sep 17 00:00:00 2001 From: Scott Bedard Date: Sat, 7 Aug 2021 00:08:45 -0500 Subject: [PATCH] extract all stickers if no turn is provided --- README.md | 2 +- src/puzzles/cube/cube.ts | 15 +++++++++------ src/puzzles/dodecaminx/dodecaminx.ts | 11 +++++++---- src/puzzles/puzzle.ts | 6 +++--- tests/puzzles/cube.spec.ts | 7 +++++++ tests/puzzles/dodecaminx.spec.ts | 7 +++++++ 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7eea1e6..55b6ef2 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ puzzle.scramble() #### `stickers` -Get all stickers effected by a turn. +Get stickers affected by a turn. If no turn notation is provided, all stickers will be returned. ```js const stickers = puzzle.stickers('R') diff --git a/src/puzzles/cube/cube.ts b/src/puzzles/cube/cube.ts index adf630e..84000b5 100644 --- a/src/puzzles/cube/cube.ts +++ b/src/puzzles/cube/cube.ts @@ -1,6 +1,6 @@ import { error } from '@/utils/function'; import { extract, inject, rotate } from '@/utils/matrix'; -import { flattenBy, isUniform, last, sample, times, without } from '@/utils/array'; +import { flattenBy, flattenDeep, isUniform, last, sample, times, without } from '@/utils/array'; import { floor, max, rand } from '@/utils/number'; import { keys } from '@/utils/object'; import { lowercase } from '@/utils/string'; @@ -203,17 +203,20 @@ export class Cube extends Puzzle { }); describe('stickers', () => { + it('all stickers', () => { + const model = new Cube({ size: 3 }); + const stickers = model.stickers(); + + expect(stickers.length).toBe((3 ** 2) * 6); + }); + it('X', () => { const model = new Cube({ size: 3 }); const stickers = model.stickers('X'); diff --git a/tests/puzzles/dodecaminx.spec.ts b/tests/puzzles/dodecaminx.spec.ts index ffd83b3..20ba6c8 100644 --- a/tests/puzzles/dodecaminx.spec.ts +++ b/tests/puzzles/dodecaminx.spec.ts @@ -128,6 +128,13 @@ describe('Dodecaminx', () => { }); describe('stickers', () => { + it('all stickers', () => { + const model = new Dodecaminx({ size: 3 }); + const stickers = model.stickers(); + + expect(stickers.length).toBe(11 * 12); + }); + it('u', () => { const model = new Dodecaminx({ size: 3 }); const stickers = model.stickers('u');