Created
November 10, 2014 20:43
-
-
Save larryv/a64c8610d75289857601 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
#!/usr/bin/env python3 | |
import itertools | |
import subprocess | |
def main(): | |
fmt_pieces = ('', '.', '{:01d}', '{:01d}.', '{:02d}', '{:02d}.') | |
# All possible combinations of four components. | |
fmts = [''.join(p) for p in itertools.product(fmt_pieces, repeat=3)] | |
# Filter out formats with adjacent numbers. | |
is_bad = lambda s: s.find('}{') != -1 | |
fmts = itertools.filterfalse(is_bad, fmts) | |
test_values = (0, 1, 5, 9, 10, 11, 20, 50, 99, 100, 101) | |
versions = list(itertools.product(test_values, repeat=3)) | |
version_strings = (f.format(*v) for f in fmts for v in versions) | |
version_strings = (key for key, group in | |
itertools.groupby(sorted(version_strings))) | |
for vs in version_strings: | |
print(vs, '->', subprocess.check_output(['./version_text', vs])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment