Skip to content

Commit

Permalink
allow for falsey center values
Browse files Browse the repository at this point in the history
closes #36
  • Loading branch information
scottbedard committed Nov 13, 2021
1 parent 234a5f0 commit 94660f3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ module.exports = {
'prefer-destructuring': 0,
'quote-props': 0,
'semi': ['error', 'never'],
'symbol-description': 0,
},
};
6 changes: 4 additions & 2 deletions src/puzzles/dodecaminx/dodecaminx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export class Dodecaminx extends Puzzle<DodecaminxOptions, DodecaminxState, Dodec
* @param {Partial<DodecaminxStateSimple>} state state to apply to the puzzle
*/
apply(state: Partial<DodecaminxStateSimple>) {
const symbol = Symbol()

keys(state).forEach(face => {
const [corners, middles, center] = state[face]
const [corners, middles, center = symbol] = state[face]

corners.forEach((matrix, i) => {
matrix.forEach((value, j) => {
Expand All @@ -83,7 +85,7 @@ export class Dodecaminx extends Puzzle<DodecaminxOptions, DodecaminxState, Dodec
})
}

if (center) {
if (center !== symbol) {
this.state[face][2].value = center
}
}
Expand Down
56 changes: 37 additions & 19 deletions tests/puzzles/dodecaminx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,46 @@ import dodecaminxNotation from './dodecaminx-notation'
import dodecaminxTurns from './dodecaminx-turns'

describe('Dodecaminx', () => {
it('apply', () => {
const model = new Dodecaminx({ size: 3 })
describe('apply', () => {
it('fills face values', () => {
const model = new Dodecaminx({ size: 3 })

model.apply({
f: [
[[-1], [-2], [-3], [-4], [-5]],
[[-6], [-7], [-8], [-9], [-10]],
-11,
],
model.apply({
f: [
[[-1], [-2], [-3], [-4], [-5]],
[[-6], [-7], [-8], [-9], [-10]],
-11,
],
})

expect(model.state.f[0][0][0].value).toBe(-1)
expect(model.state.f[0][1][0].value).toBe(-2)
expect(model.state.f[0][2][0].value).toBe(-3)
expect(model.state.f[0][3][0].value).toBe(-4)
expect(model.state.f[0][4][0].value).toBe(-5)
expect(model.state.f[1][0][0].value).toBe(-6)
expect(model.state.f[1][1][0].value).toBe(-7)
expect(model.state.f[1][2][0].value).toBe(-8)
expect(model.state.f[1][3][0].value).toBe(-9)
expect(model.state.f[1][4][0].value).toBe(-10)
expect(model.state.f[2].value).toBe(-11)
})

expect(model.state.f[0][0][0].value).toBe(-1)
expect(model.state.f[0][1][0].value).toBe(-2)
expect(model.state.f[0][2][0].value).toBe(-3)
expect(model.state.f[0][3][0].value).toBe(-4)
expect(model.state.f[0][4][0].value).toBe(-5)
expect(model.state.f[1][0][0].value).toBe(-6)
expect(model.state.f[1][1][0].value).toBe(-7)
expect(model.state.f[1][2][0].value).toBe(-8)
expect(model.state.f[1][3][0].value).toBe(-9)
expect(model.state.f[1][4][0].value).toBe(-10)
expect(model.state.f[2].value).toBe(-11)
it('can apply falsey center values', () => {
const model = new Dodecaminx({ size: 3 })

expect(model.state.b[2].value).not.toBe(null)

model.apply({
b: [
[[null], [null], [null], [null], [null]],
[[null], [null], [null], [null], [null]],
null,
],
})

expect(model.state.b[2].value).toBe(null)
})
})

it('clone', () => {
Expand Down

0 comments on commit 94660f3

Please sign in to comment.