Created
October 9, 2012 18:38
-
-
Save eigenhombre/3860597 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import binascii | |
| import hashlib | |
| import random | |
| import json | |
| import bz2 | |
| def mbid(pos): | |
| h = hashlib | |
| return h.sha224(str(pos)).hexdigest()[:10] | |
| def sim_config(name, strings=86, doms_per_str=60, domfrac=1.0): | |
| return {'config': name, | |
| 'strings': [{'str': s + 1, | |
| 'doms': [{mbid(d + 1): d + 1} | |
| for d in range(doms_per_str) | |
| if random.random() < domfrac]} | |
| for s in range(strings)]} | |
| def test_config_barf(): | |
| cfg = sim_config('sim') | |
| dumped = json.dumps(cfg) | |
| compressed = bz2.compress(dumped) | |
| hexed = binascii.hexlify(compressed) | |
| unhexed = binascii.unhexlify(hexed) | |
| uncompressed = bz2.decompress(unhexed) | |
| undumped = json.loads(uncompressed) | |
| assert undumped == cfg | |
| print len(dumped), len(compressed), len(hexed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment