mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
refactor(player): E.3 — extract waveform/normalization/seek pure helpers (#566)
Three small tranches out of playerStore.ts: - src/utils/waveformParse.ts — waveformBlobLenOk + coerceWaveformBins (the parser that handles number[] / Uint8Array / ArrayLike payloads Rust serializes as). - src/utils/normalizationCompare.ts — normalizationAlmostEqual (tolerant null-aware dB comparison). - src/utils/seekErrors.ts — isRecoverableSeekError (retry classifier for the Rust seek pipeline). Each gets focused unit tests. All four were file-private, no external callers — pure code move. playerStore 3556 → 3516 LOC.
This commit is contained in:
committed by
GitHub
parent
1521e4ea8f
commit
d24514d67e
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { normalizationAlmostEqual } from './normalizationCompare';
|
||||
|
||||
describe('normalizationAlmostEqual', () => {
|
||||
it('returns true for two nulls', () => {
|
||||
expect(normalizationAlmostEqual(null, null)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for mixed null / number', () => {
|
||||
expect(normalizationAlmostEqual(null, 0)).toBe(false);
|
||||
expect(normalizationAlmostEqual(0, null)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for values within the default epsilon (0.12)', () => {
|
||||
expect(normalizationAlmostEqual(-14.0, -14.05)).toBe(true);
|
||||
expect(normalizationAlmostEqual(-14.0, -14.12)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false just past the default epsilon', () => {
|
||||
expect(normalizationAlmostEqual(-14.0, -14.13)).toBe(false);
|
||||
});
|
||||
|
||||
it('honours a custom epsilon', () => {
|
||||
expect(normalizationAlmostEqual(-14.0, -14.5, 1.0)).toBe(true);
|
||||
expect(normalizationAlmostEqual(-14.0, -14.5, 0.4)).toBe(false);
|
||||
});
|
||||
|
||||
it('treats exact equality as equal', () => {
|
||||
expect(normalizationAlmostEqual(-10, -10)).toBe(true);
|
||||
expect(normalizationAlmostEqual(0, 0)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user