Skip to content

Instantly share code, notes, and snippets.

@larryv
Created November 10, 2014 20:43
Show Gist options
  • Save larryv/a64c8610d75289857601 to your computer and use it in GitHub Desktop.
Save larryv/a64c8610d75289857601 to your computer and use it in GitHub Desktop.
#!/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