test1.py 804 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python3
  2. from rfc1982_serial_number import Serial, find_intermediate
  3. from argparse import ArgumentParser
  4. from random import randint
  5. ap = ArgumentParser()
  6. ap.add_argument("iterations", type = int, default = 100000, nargs = "?")
  7. args = ap.parse_args()
  8. for test in range(args.iterations):
  9. i1 = Serial(randint(0, Serial.modulus - 1))
  10. i2 = Serial(randint(0, Serial.modulus - 1))
  11. assert i1 == i2 or \
  12. (i1 < i2 and not (i1 > i2)) or \
  13. (i1 > i2 and not (i1 < i2)) or \
  14. int(i1) ^ int(i2) == Serial.modulus >> 1
  15. step = [i1, i2]
  16. for wrap in find_intermediate(i1, i2):
  17. assert wrap > step[-2]
  18. step.insert(-1, wrap)
  19. for i in range(len(step) - 1):
  20. assert step[i] < step[i + 1]
  21. print(" => ".join(str(s) for s in step))