Debian Codegraph @

tests/test_hex_2.py

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