Created
April 24, 2018 15:32
-
-
Save DUznanski/70c623303293ba21bc68a0c33549422d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# random-fill testing: | |
def makes_sufficently_large_table(): | |
unittest.assertEqual(generate_choices([('a',2),('b',1),('c',2)]), ['a','a','b','c','c']) | |
# ... similar. Include, among others, things with fallbacks that don't get used. | |
def fills_small_table(): | |
choices = generate_choices([('a',2),('b',1),('c',0),('d',0)]) | |
# make sure the first part is all the ones with known frequencies | |
# this actually suggests that what we really want is to break this down into more functions: | |
# generate_static_choices makes the deterministic part of the table, for one thing | |
unittest.assertEqual(choices[:3], ['a','a','b']) | |
unittest.assertIn(choices[3], ['c','d']) | |
# now if we want to go to town, do this a bunch of times | |
# 30 times over for 2 fallbacks should do | |
# for larger numbers of fallbacks, you'll want a somewhat larger target. | |
# something something coupon collector's problem | |
# but with 30 tries we have approx. a 1 in a billion chance of it failing randomly. | |
fallbacks = set() | |
for k in range(30): | |
fallbacks.add(generate_choices([('a',2),('b',1),('c',0),('d',0)])[3]) | |
unittest.assertEqual(fallbacks, {'c', 'd'}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment