Skip to content

Commit

Permalink
throw error on prime double turns
Browse files Browse the repository at this point in the history
fixes #29
  • Loading branch information
scottbedard committed Aug 8, 2021
1 parent e3058ba commit 88ad0df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/puzzles/cube/cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class Cube extends Puzzle<CubeOptions, CubeState, CubeSimpleState, CubeTu
* @param {string} turn turn notation to parse
*/
parse(turn: string): CubeTurn {
const parts = turn.match(/^(\d)*([ulfrbdxyzULFRBDXYZ]){1}(w)*(['-2])*$/);
const parts = turn.match(/^(\d)*([ulfrbdxyzULFRBDXYZ]){1}(w)*(['-2])?$/);

if (!parts) {
error(`Invalid turn: ${turn}`);
Expand Down
28 changes: 18 additions & 10 deletions tests/puzzles/cube.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,26 @@ describe('Cube', () => {
const debug = '';
const model = new Cube({ size: 3 });

Object.entries(cubeNotation).forEach(([turn, expected]) => {
if (!debug || debug === turn) {
it(turn, () => {
expect(model.parse(turn)).toEqual(expected);
});
} else {
it.todo(turn);
}
describe('valid', () => {
Object.entries(cubeNotation).forEach(([turn, expected]) => {
if (!debug || debug === turn) {
it(turn, () => {
expect(model.parse(turn)).toEqual(expected);
});
} else {
it.todo(turn);
}
});
});

it('bad turn', () => {
expect(() => model.parse('bad turn')).toThrow();
describe('invalid', () => {
it('bad turn', () => {
expect(() => model.parse('bad turn')).toThrow();
});

it('R2-', () => {
expect(() => model.parse('R2-')).toThrow();
});
});
});

Expand Down

0 comments on commit 88ad0df

Please sign in to comment.