Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cube/CubeMoves.res
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ let scrambleScale = length =>
// slice fixed), and a first inner turn on 4x4 and larger. `random` returns
// numbers in [0, 1).
let generateScrambleMoves = (size, options: scrambleOptions, random: unit => float) => {
let base = scrambleLengths[size - 2]->Option.getOr(20)
// Above the table (7x7 = 100 moves) the length grows with the sticker count.
let base =
scrambleLengths[size - 2]->Option.getOr(
size > 7 ? Math.round(100.0 *. Int.toFloat(size * size) /. 49.0)->Float.toInt : 20,
)
let scale = scrambleScale(options.length->Option.getOr(Normal))
let length = Math.round(Int.toFloat(base) *. scale)->Float.toInt
let maxDepth = options.innerLayers->Option.getOr(true) ? size / 2 : 1
Expand Down
13 changes: 7 additions & 6 deletions test/axisColorFrame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
initialColorFrame,
} from '../src/core/view/AxisGizmo.gen'
import { createSolvedCube } from '../src/cube/cubeAssembly'
import { EVEN_SIZES, ODD_SIZES } from './cubeSizes'
import {
applyCubeLayerMove,
generateScrambleMoves,
Expand All @@ -19,14 +20,14 @@ const standardFrame = {
}

describe('axis color reference frame', () => {
it.each([2, 4, 6])('uses a logical frame for a mixed %i cube', (size) => {
it.each(EVEN_SIZES)('uses a logical frame for a mixed %i cube', (size) => {
let cube = createSolvedCube(size)
for (const face of ['U', 'R', 'F', 'D'] as const)
cube = applyCubeLayerMove(cube, size, face, 1, 1, 1)
expect(initialColorFrame(cube, size)).toEqual(standardFrame)
})

it.each([2, 4, 6])(
it.each(EVEN_SIZES)(
'keeps the %i cube frame through face, inner and wide turns',
(size) => {
let frame = initialColorFrame(createSolvedCube(size), size)
Expand All @@ -39,7 +40,7 @@ describe('axis color reference frame', () => {
},
)

it.each([2, 4, 6])('rotates the %i cube frame with x, y and z', (size) => {
it.each(EVEN_SIZES)('rotates the %i cube frame with x, y and z', (size) => {
const start = initialColorFrame(createSolvedCube(size), size)
const x = advanceColorFrame(start, size, 'R', size, 1, size)
const y = advanceColorFrame(start, size, 'U', size, 1, size)
Expand All @@ -50,7 +51,7 @@ describe('axis color reference frame', () => {
expect(advanceColorFrame(y, size, 'U', size, -1, size)).toEqual(start)
})

it.each([3, 5, 7])(
it.each(ODD_SIZES)(
'preserves the middle-slice reference change on a %i cube',
(size) => {
const start = initialColorFrame(createSolvedCube(size), size)
Expand All @@ -74,7 +75,7 @@ describe('axis color reference frame', () => {
expect(initialColorFrame(rotated, 3)).toMatchObject({ u: 'W', f: 'R' })
})

it.each([3, 5, 7])(
it.each(ODD_SIZES)(
'tracks fixed centers through a sequence of %i cube turns',
(size) => {
let cube = createSolvedCube(size)
Expand Down Expand Up @@ -110,7 +111,7 @@ describe('axis color reference frame', () => {
},
)

it.each([2, 4, 6])(
it.each(EVEN_SIZES)(
'restores the %i cube frame with inverse moves and ignores Scramble turns',
(size) => {
const initial = initialColorFrame(createSolvedCube(size), size)
Expand Down
58 changes: 31 additions & 27 deletions test/captureFaceMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
validateMapping,
} from '../src/client/capture/captureFaceMapping'
import { rotateGrid, turnFace, type Faces } from '../src/cube/cubeGeometry'
import { ALL_SIZES, ODD_SIZES } from './cubeSizes'

const ORDER = ['U', 'R', 'F', 'D', 'L', 'B'] as const
const COLORS = ['W', 'R', 'G', 'Y', 'O', 'B']
Expand All @@ -24,7 +25,7 @@ const asymmetric = (n: number) => turnFace(turnFace(solved(n), 'R', 1), 'U', 1)

// Source photos are capture slots, not the cube sides named by these keys.
describe('manual captured-face mapping', () => {
for (const n of [3, 5, 7]) {
for (const n of ODD_SIZES) {
it(`uses fixed centers and preserves every quarter turn on an odd ${n}x${n}`, () => {
const faces = asymmetric(n)
const raw = Object.fromEntries(
Expand Down Expand Up @@ -281,35 +282,38 @@ describe('recorded 7x7 capture and persisted display transforms', () => {
})
})

it('conjugates every face direction and representative layer depth exactly through all display frames', () => {
const key = (faces: Faces) =>
ORDER.map((face) => faces[face].flat().join('')).join('|')
for (const n of [2, 3, 4, 5, 6, 7, 8]) {
let original = asymmetric(n)
original = turnFace(turnFace(original, 'F', -1), 'L', 2)
const widths = [...new Set([1, Math.ceil(n / 2), n])]
for (const width of widths) {
for (const quarters of [1, -1, 2]) {
const legal = new Set(
ORDER.map((face) => key(turnFace(original, face, quarters, width))),
)
for (let index = 0; index < 24; index++) {
const displayed = transformFaces(original, index)!
const inverse = inverseTransform(index)!
for (const face of ORDER) {
const displayedMove = turnFace(displayed, face, quarters, width)
const canonical = transformFaces(displayedMove, inverse)!
expect(
legal.has(key(canonical)),
`N=${n}, frame=${index}, ${face}/${quarters}/${width}`,
).toBe(true)
expect(transformFaces(canonical, index)).toEqual(displayedMove)
for (const n of ALL_SIZES)
describe(`${n}x${n} display frames`, () => {
const key = (faces: Faces) =>
ORDER.map((face) => faces[face].flat().join('')).join('|')
// One test per size: the work grows with the size (about 15 s at 15x15 on a
// busy machine), so each size gets its own time limit.
it('conjugates every face direction and representative layer depth exactly through all display frames', () => {
let original = asymmetric(n)
original = turnFace(turnFace(original, 'F', -1), 'L', 2)
const widths = [...new Set([1, Math.ceil(n / 2), n])]
for (const width of widths) {
for (const quarters of [1, -1, 2]) {
const legal = new Set(
ORDER.map((face) => key(turnFace(original, face, quarters, width))),
)
for (let index = 0; index < 24; index++) {
const displayed = transformFaces(original, index)!
const inverse = inverseTransform(index)!
for (const face of ORDER) {
const displayedMove = turnFace(displayed, face, quarters, width)
const canonical = transformFaces(displayedMove, inverse)!
expect(
legal.has(key(canonical)),
`N=${n}, frame=${index}, ${face}/${quarters}/${width}`,
).toBe(true)
expect(transformFaces(canonical, index)).toEqual(displayedMove)
}
}
}
}
}
}
}, 30_000)
}, 60_000)
})

it('prefills the current nonidentity even candidate instead of falling back to zero rotations', () => {
const candidateFaces = asymmetric(4)
Expand Down
3 changes: 2 additions & 1 deletion test/captureRecoveryPersistence.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest'
import { ALL_SIZES } from './cubeSizes'
import {
captureFrame,
validateMapping,
Expand Down Expand Up @@ -60,7 +61,7 @@ const setup = (n: number) => {
}

describe('versioned exact face recovery', () => {
for (const n of [2, 3, 4, 5, 6, 7, 8])
for (const n of ALL_SIZES)
it(`retains explicit slots, all rotations and capture pose for ${n}x${n}`, () => {
const { raw, faces, record } = setup(n)
const before = JSON.stringify(raw)
Expand Down
7 changes: 4 additions & 3 deletions test/cube/cubeAssembly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
pickWizardFace,
} from '../../src/cube/orientationWizard'
import { runFullParity } from '../../src/cube/parity'
import { EVEN_SIZES, ODD_SIZES } from '../cubeSizes'

const SOLVED_COLOR: Record<string, string> = {
U: 'W',
Expand Down Expand Up @@ -94,7 +95,7 @@ function captureWithRotations(
}

describe('solveFaceOrientations', () => {
it.each([3, 5, 7])(
it.each(ODD_SIZES)(
'resolves a solved %ix%i cube with zero rotation and full validity',
(size) => {
const result = solveFaceOrientations(solvedFaces(size))
Expand All @@ -106,7 +107,7 @@ describe('solveFaceOrientations', () => {
},
)

it.each([3, 5, 7])(
it.each(ODD_SIZES)(
'recovers a real one-move scramble (%ix%i, U turn) at full validity',
(size) => {
const captured = captureWithRotations(uTurnedFaces(size), {
Expand Down Expand Up @@ -273,7 +274,7 @@ describe('solveFaceOrientations', () => {
})

describe('even sizes (no fixed center reference - identity searched jointly with rotation)', () => {
it.each([2, 4, 6])(
it.each(EVEN_SIZES)(
'resolves a solved %ix%i cube, shuffled and pre-rotated, to full validity',
(size) => {
// Even sizes have no center to key off, so - unlike the odd-size
Expand Down
7 changes: 5 additions & 2 deletions test/cube/cubeGeometry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
solveFaceOrientations,
type FaceKey,
} from '../../src/cube/cubeAssembly'
import { ALL_SIZES } from '../cubeSizes'

const WCA: Record<FaceKey, string> = {
U: 'W',
Expand Down Expand Up @@ -99,14 +100,16 @@ describe('rotateCube', () => {
})

describe('scrambles read as valid cubes', () => {
for (const n of [2, 3, 4, 5, 6, 7]) {
for (const n of ALL_SIZES) {
// Even sizes search identity and rotation jointly: 1 to 3 s per size, so
// the default 5 s limit is too tight on a busy runner.
it(`${n}x${n}`, () => {
for (let seed = 1; seed <= 5; seed++) {
const cube = scramble(n, 30, seed * 31 + n)
const solved = solveFaceOrientations(cube)!
expect(solved.fullyValid, `seed ${seed}`).toBe(true)
}
})
}, 60_000)
}
})

Expand Down
15 changes: 9 additions & 6 deletions test/cube/guidedCapture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
type GuidedCapture,
} from '../../src/cube/cubeAssembly'
import { preferredGuidedArrangementIndex } from '../../src/cube/orientationWizard'
import { ALL_SIZES, ODD_SIZES } from '../cubeSizes'

const WCA: Record<FaceKey, string> = {
U: 'W',
Expand Down Expand Up @@ -140,7 +141,7 @@ const sameCube = (a: Faces, b: Faces) => {
}

describe('solveGuidedCapture', () => {
for (const n of [2, 3, 4, 5, 6, 7]) {
for (const n of ALL_SIZES) {
it(`reassembles scrambled ${n}x${n} cubes however they were held, turned and tipped`, () => {
const rand = rng(1000 + n)
for (let trial = 0; trial < 6; trial++) {
Expand All @@ -159,7 +160,9 @@ describe('solveGuidedCapture', () => {
`trial ${trial}`,
).toBe(true)
}
})
// 1 to 9 s per size on a busy machine (6 trials of the joint search);
// the default 5 s limit is too tight above 7x7.
}, 120_000)
}

it('presents odd sizes in standard orientation (white on top, green in front)', () => {
Expand Down Expand Up @@ -252,7 +255,7 @@ describe('predictGuidedCenters', () => {
const face = (n: number, color: string) =>
Array.from({ length: n }, () => Array(n).fill(color))

for (const n of [3, 5, 7, 9, 11, 13, 15]) {
for (const n of ODD_SIZES) {
it(`shows the opposite after one ${n}x${n} face, then all remaining centers after adjacent faces`, () => {
const first = face(n, 'G'),
second = face(n, 'R')
Expand Down Expand Up @@ -284,7 +287,7 @@ describe('predictGuidedCenters', () => {
})
}

for (const n of [3, 5, 7, 9, 11, 13, 15]) {
for (const n of ODD_SIZES) {
it(`reserves center slots and routes faces by center on ${n}x${n}`, () => {
const first = face(n, 'G'),
second = face(n, 'R')
Expand Down Expand Up @@ -360,7 +363,7 @@ describe('center-routed capture slots', () => {
const face = (n: number, color: string) =>
Array.from({ length: n }, () => Array(n).fill(color))

for (const n of [3, 5, 7]) {
for (const n of ODD_SIZES) {
it(`keeps the first two ${n}x${n} photos and routes later faces regardless of arrival order`, () => {
const photos: Array<string[][] | undefined> = Array(6).fill(undefined)
expect(captureSlotForCenter(photos, 4, face(n, 'O'))).toBe(0)
Expand Down Expand Up @@ -471,7 +474,7 @@ describe('center-routed capture slots', () => {
})

describe('findRepeatedFaces', () => {
for (const n of [2, 3, 4, 7]) {
for (const n of ALL_SIZES) {
it(`finds a ${n}x${n} face photographed twice, even turned and (from 3x3 up) with a misread`, () => {
const capture = photograph(
scramble(n, 40, rng(20 + n)),
Expand Down
5 changes: 3 additions & 2 deletions test/cube/notation/notationOutput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
wrgFaceletsToGrids,
type cubeState as CubeState,
} from '../../../src/cube/notation/NotationOutput.gen'
import { ALL_SIZES } from '../../cubeSizes'

function solvedCube(size: number): CubeState {
const face = (color: string) => Array(size * size).fill(color)
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('fromWRGFacelets', () => {
})

it('round-trips toWRGFacelets output for every supported puzzle size', () => {
for (const size of [2, 3, 4, 5, 6, 7]) {
for (const size of ALL_SIZES) {
const cube = solvedCube(size)
expect(fromWRGFacelets(toWRGFacelets(cube))).toEqual(cube)
}
Expand Down Expand Up @@ -163,7 +164,7 @@ describe('fromURFFacelets', () => {
})

it('round-trips toURFFacelets output for every supported puzzle size', () => {
for (const size of [2, 3, 4, 5, 6, 7]) {
for (const size of ALL_SIZES) {
const cube = solvedCube(size)
expect(fromURFFacelets(toURFFacelets(cube))).toEqual(cube)
}
Expand Down
3 changes: 2 additions & 1 deletion test/cubeShadow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest'
import { ALL_SIZES } from './cubeSizes'
import {
SHADOW_OUTLINE_POINTS,
paddedOutline,
Expand Down Expand Up @@ -39,7 +40,7 @@ describe('cube shadow', () => {
})

it('lies on a floor below the cube in every orientation', () => {
for (const n of [2, 3, 7]) {
for (const n of ALL_SIZES) {
const radius = (n / 2) * Math.sqrt(3)
expect(shadowFloorY(n)).toBeLessThan(-radius)
}
Expand Down
5 changes: 5 additions & 0 deletions test/cubeSizes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// The cube sizes the app accepts, 2 through 15, and their parities. Tests that
// loop over sizes import these so the range lives in one place.
export const ALL_SIZES = Array.from({ length: 14 }, (_, i) => i + 2)
export const ODD_SIZES = ALL_SIZES.filter((n) => n % 2 === 1)
export const EVEN_SIZES = ALL_SIZES.filter((n) => n % 2 === 0)
Loading
Loading