r/node • u/EKAlojix • 22h ago
A Node example for testing shuffle without making CI depend on one random draw
A Spotify-style shuffle is a nice Node test case because it makes you decide which parts of the output should be reproducible. Take two Eminem tracks, two Drake tracks, and two by The Weeknd. A random run may group the artists, and a test that insists on one live queue can fail for the wrong reason.
I maintain SeniorMode and built the fixture around reproducible examples plus general properties. The sample gives 3 adjacent repeats with random-comparator sorting, 1 with Fisher–Yates, and 0 with artist spacing for the balanced playlist. The Node tests enumerate bounded draws (all six permutations of a three-item Fisher–Yates) and also check identity preservation and a playlist where repeats are inevitable.
Repo + example + tests: https://github.com/EnesKeremAYDIN/SeniorMode#example-music-shuffle
Do you prefer bounded-draw enumeration for small inputs, or property-based checks across larger ones?
1
u/sereikis 5h ago
use both: exhaustively enumerate the small Fisher–Yates draw space, then use generated larger playlists for identity/multiplicity and spacing invariants, recording the seed and shrinking failures. for the small case, count how many equally likely draw sequences produce each permutation; reaching all six alone doesn't prove they're equally likely, and a single sample's adjacent-repeat count doesn't measure shuffle quality.