[Python-checkins] r54259 - sandbox/trunk/pep3101/test_simpleformat.py sandbox/trunk/pep3101/unicodeformat.c
eric.smith
python-checkins at python.org
Sat Mar 10 13:38:48 CET 2007
Author: eric.smith
Date: Sat Mar 10 13:38:46 2007
New Revision: 54259
Modified:
sandbox/trunk/pep3101/test_simpleformat.py
sandbox/trunk/pep3101/unicodeformat.c
Log:
Added test cases for 2's compliment algorithm in binary converter.
Modified: sandbox/trunk/pep3101/test_simpleformat.py
==============================================================================
--- sandbox/trunk/pep3101/test_simpleformat.py (original)
+++ sandbox/trunk/pep3101/test_simpleformat.py Sat Mar 10 13:38:46 2007
@@ -308,6 +308,32 @@
# error in writing the digits might write over the parens
self.formatEqualsWithUnicode("(" + s + ")", "{0:()b}", -i)
+ def test_from_str(s):
+ n = int(s, 2)
+ self.formatEqualsWithUnicode(s, "{0:b}", n)
+ self.formatEqualsWithUnicode("-" + s, "{0:b}", -n)
+ self.formatEqualsWithUnicode("(" + s + ")", "{0:()b}", -n)
+
+ # test the 2's compliment algorithm
+ # it has a special test for all ones inside a byte, so test
+ # byte aligned strings of ones
+ test_from_str("1" * 8)
+ test_from_str("1" + "1" * 8)
+ test_from_str("10" + "1" * 8)
+ test_from_str("1" * 8 + "0" * 8)
+ test_from_str("1" + "1" * 8 + "0" * 8)
+ test_from_str("10" + "1" * 8 + "0" * 8)
+ test_from_str("1" * 8 + "0" * 8 + "1" * 8)
+ test_from_str("1" + "1" * 8 + "0" * 8 + "1" * 8)
+ test_from_str("10" + "1" * 8 + "0" * 8 + "1" * 8)
+ test_from_str("1" * 16)
+ test_from_str("1" + "1" * 16)
+ test_from_str("10" + "1" * 16)
+ test_from_str("1" * 16 + "0" * 8)
+ test_from_str("1" + "1" * 16 + "0" * 8)
+ test_from_str("10" + "1" * 16 + "0" * 8)
+
+
def test_number_specifier(self):
def test(value):
self.formatEqualsWithUnicode(locale.format("%f", value), "{0:n}", value)
Modified: sandbox/trunk/pep3101/unicodeformat.c
==============================================================================
--- sandbox/trunk/pep3101/unicodeformat.c (original)
+++ sandbox/trunk/pep3101/unicodeformat.c Sat Mar 10 13:38:46 2007
@@ -52,6 +52,10 @@
#if PYTHON_API_VERSION < 1013
typedef int Py_ssize_t;
#define Py_LOCAL_INLINE(x) static x
+
+#define PySet_Discard PyDict_DelItem
+#define PySet_New PyDict_Copy
+#define PySet_GET_SIZE PyDict_Size
#endif
/* Defines for more efficiently reallocating the string buffer */
@@ -59,12 +63,6 @@
#define SIZE_MULTIPLIER 2
#define MAX_SIZE_INCREMENT 3200
-#if PYTHON_API_VERSION < 1013
-#define PySet_Discard PyDict_DelItem
-#define PySet_New PyDict_Copy
-#define PySet_GET_SIZE PyDict_Size
-#endif
-
/* MAXLEN_INT_STRING is the maximum length of an integer represented
* as a string, in base 10. The analysis in stringobject.c shows that
@@ -1333,7 +1331,8 @@
} else if (PyUnicode_Check(fieldobj)) {
CH_TYPE *ubuf;
int len;
- if (!PyArg_Parse(fieldobj, "u#;\"c\" format requires int or char", &ubuf, &len))
+ if (!PyArg_Parse(fieldobj, "u#;\"c\" format requires int or char",
+ &ubuf, &len))
return 0;
if (len != 1) {
More information about the Python-checkins
mailing list