arialdo,
@arialdo@mastodon.online avatar

How would you write a test to verify that the function

shuffleList xs

returns the list xs with shuffled items?
Even more generally, how to write tests of functions having to do with randomicity?

BoydStephenSmithJr,
@BoydStephenSmithJr@hachyderm.io avatar

@arialdo First, use formal methods and the implementation to prove the output is always a permutation of the input.

Then, shuffle a small list a large number of times and verify the distribution is uniform. Other, more complex tests of random number generators can also be adapted and used. Since, for any finite input, repeated calls to shuffle is effectively a RNG.

Might be able to use parametricity to extend finite results to infinite lists?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines