1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Test the shorthand #abc hex expansion """
import time
from colored.hexadecimal import Hex
def main():
""" Contribution by Fredrik Klasson. """
hexad = Hex()
all_ok = True
try:
T_sta = time.perf_counter()
for r in range(0, 0xF):
for g in range(0, 0xF):
for b in range(0, 0xF):
short = '#%x%x%x' % (r, g, b)
long = '#%x%x%x%x%x%x' % (r, r, g, g, b, b)
all_ok = all_ok and hexad.find(long) == hexad.find(short)
print('.', end='')
print('')
dT = time.perf_counter() - T_sta
print('Lookup time: %0.4f s => %0.4f s/lookup' % (dT, dT / (2 * 0xF * 0xF * 0xF)))
print('pass' if all_ok else 'FAILED')
except Exception as e:
print('Whopsie, something %s-ish went wrong: %s' % (e.__class__.__name__, e))
import traceback
traceback.print_exc()
all_ok = False
return all_ok
if __name__ == "__main__":
ok = main()
exit(0 if ok else 1)
|