Rob Austein 7 mēneši atpakaļ
vecāks
revīzija
cca4a4ce8f
3 mainītis faili ar 12 papildinājumiem un 16 dzēšanām
  1. 2 2
      README.md
  2. 2 3
      rfc1982_serial_number.py
  3. 8 11
      test2.py

+ 2 - 2
README.md

@@ -13,8 +13,8 @@ addition and comparision, both within a restricted range specified
 by the RFC.
 
 The default modulus is `2**32`, you can change this by subclassing the
-`Serial` and overriding the class's `modulus` variable.  The modulus
-must be a power of two.
+`Serial` class and overriding the `modulus` variable in the subclass.
+The modulus must be a power of two.
 
 See RFC 1982 for discussion of the ways in which serial numbers do not
 work like normal integers.  In particular, note that there's a corner

+ 2 - 3
rfc1982_serial_number.py

@@ -19,15 +19,14 @@ class Serial:
     by the RFC.
 
     The default modulus is 2**32, you can change this by subclassing
-    the Serial class and overriding the class's modulus variable.  The
-    modulus must be a power of two.
+    the Serial class and overriding the subclass's modulus variable.
+    The modulus must be a power of two.
 
     See RFC 1982 for discussion of the ways in which Serial numbers do
     not work like normal integers.  In particular, note that there's a
     corner case in which one can have a pair of Serial numbers I1 and
     I2 where I1 is neither equal to, less than, nor greater than I2.
     This is deliberate and is not a bug in the code.  See the RFC.
-
     """
 
     modulus = 2 ** 32

+ 8 - 11
test2.py

@@ -4,21 +4,18 @@ from rfc1982_serial_number import Serial
 from random import randint
 from subprocess import run
 
-def test(n, cmd):
-    print(f"\nTest: {test}: {cmd[0]} {cmd[1]} {cmd[2]}")
+def test(n, i1, i2):
+    cmd = ("./rfc1982_serial_number.py", str(i1), str(i2))
+    print(f"\nTest: {n}: {cmd[0]} {cmd[1]} {cmd[2]}")
     run(cmd)
 
 for n in range(100):
-    i1 = randint(0, Serial.modulus - 1)
-    i2 = randint(0, Serial.modulus - 1)
-    test(n, ("./rfc1982_serial_number.py", str(i1), str(i2)))
+    test(n, randint(0, Serial.modulus - 1), randint(0, Serial.modulus - 1))
 
 for n in range(10):
-    i1 = randint(0, Serial.modulus - 1)
-    i2 = i1 ^ (Serial.modulus >> 1)
-    test(n, ("./rfc1982_serial_number.py", str(i1), str(i2)))
+    t = randint(0, Serial.modulus - 1)
+    test(n, t, t ^ (Serial.modulus >> 1))
 
 for n in range(10):
-    i1 = randint(0, Serial.modulus - 1)
-    i2 = (i1 + Serial.modulus - 1) & (Serial.modulus - 1)
-    test(n, ("./rfc1982_serial_number.py", str(i1), str(i2)))
+    t = randint(0, Serial.modulus - 1)
+    test(n, t, (t + Serial.modulus - 1) & (Serial.modulus - 1))