summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rwxr-xr-xrfc1982_serial_number.py5
-rwxr-xr-xtest2.py19
3 files changed, 12 insertions, 16 deletions
diff --git a/README.md b/README.md
index 3537697..2d952c3 100644
--- a/README.md
+++ b/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
diff --git a/rfc1982_serial_number.py b/rfc1982_serial_number.py
index bb9988c..7b9b845 100755
--- a/rfc1982_serial_number.py
+++ b/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
diff --git a/test2.py b/test2.py
index 2db8a70..5d769c0 100755
--- a/test2.py
+++ b/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))