From 57187c621d8a97fe68b2d302812b2c8f7a567a66 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 23 May 2012 09:18:40 +0200 Subject: [PATCH] Added test for identifier/numeric conversion --- testing/numerics.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 testing/numerics.py diff --git a/testing/numerics.py b/testing/numerics.py new file mode 100644 index 0000000..ed0aa98 --- /dev/null +++ b/testing/numerics.py @@ -0,0 +1,12 @@ +import math + +def to_numeric(identifier): + return ((ord(identifier[:1]) - 1) * 255) + (ord(identifier[1:]) - 1) + +def to_identifier(numeric): + return chr(int(math.floor(numeric / 255) + 1)) + chr((numeric % 255) + 1) + +print to_identifier(to_numeric("aa")) +print to_identifier(to_numeric("ab")) +print to_identifier(to_numeric("ac")) +print to_identifier(to_numeric("ad"))