Skip to content

Commit d4315a6

Browse files
committed
float/string_format: Split large test in 2.
1 parent 2850e7c commit d4315a6

2 files changed

Lines changed: 106 additions & 104 deletions

File tree

tests/float/string_format.py

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Change the following to True to get a much more comprehensive set of tests
2-
# to run, albeit, which take considerably longer.
3-
4-
full_tests = False
5-
61
def test(fmt, *args):
72
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
83

@@ -38,105 +33,6 @@ def test(fmt, *args):
3833
#print("%.2f" % (1.750000 % 0.08333333333))
3934
#print("%.12f" % (1.750000 % 0.08333333333))
4035

41-
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
42-
fmt = '{'
43-
if conv:
44-
fmt += '!'
45-
fmt += conv
46-
fmt += ':'
47-
if alignment:
48-
fmt += fill
49-
fmt += alignment
50-
fmt += sign
51-
fmt += prefix
52-
fmt += width
53-
if precision:
54-
fmt += '.'
55-
fmt += precision
56-
fmt += type
57-
fmt += '}'
58-
test(fmt, arg)
59-
if fill == '0' and alignment == '=':
60-
fmt = '{:'
61-
fmt += sign
62-
fmt += prefix
63-
fmt += width
64-
if precision:
65-
fmt += '.'
66-
fmt += precision
67-
fmt += type
68-
fmt += '}'
69-
test(fmt, arg)
70-
71-
eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0,
72-
-0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10,
73-
1e37, -1e37, 1e-37, -1e-37,
74-
1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0,
75-
1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8,
76-
-1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0,
77-
-1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8)
78-
79-
if full_tests:
80-
for type in ('e', 'E', 'g', 'G', 'n'):
81-
for width in ('', '4', '6', '8', '10'):
82-
for alignment in ('', '<', '>', '=', '^'):
83-
for fill in ('', '@', '0', ' '):
84-
for sign in ('', '+', '-', ' '):
85-
for prec in ('', '1', '3', '6'):
86-
for num in eg_nums:
87-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
88-
89-
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
90-
# rounds differently than print("%.3f", 1.2345);
91-
92-
f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0,
93-
0.0012, 0.0123, 0.1234, 1.23459, 12.3456,
94-
-0.0001, -0.001, -0.01, -0.1, -1.0, -10.0,
95-
-0.0012, -0.0123, -0.1234, -1.23459, -12.3456)
96-
97-
if full_tests:
98-
for type in ('f', 'F'):
99-
for width in ('', '4', '6', '8', '10'):
100-
for alignment in ('', '<', '>', '=', '^'):
101-
for fill in ('', ' ', '0', '@'):
102-
for sign in ('', '+', '-', ' '):
103-
# An empty precision defaults to 6, but when uPy is
104-
# configured to use a float, we can only use a
105-
# precision of 6 with numbers less than 10 and still
106-
# get results that compare to CPython (which uses
107-
# long doubles).
108-
for prec in ('1', '2', '3'):
109-
for num in f_nums:
110-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
111-
for num in int_nums2:
112-
test_fmt('', fill, alignment, sign, '', width, '', type, num)
113-
114-
pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99)
115-
pct_nums2 = (True, False, 1, 0, -1)
116-
117-
if full_tests:
118-
type = '%'
119-
for width in ('', '4', '6', '8', '10'):
120-
for alignment in ('', '<', '>', '=', '^'):
121-
for fill in ('', ' ', '0', '@'):
122-
for sign in ('', '+', '-', ' '):
123-
# An empty precision defaults to 6, but when uPy is
124-
# configured to use a float, we can only use a
125-
# precision of 6 with numbers less than 10 and still
126-
# get results that compare to CPython (which uses
127-
# long doubles).
128-
for prec in ('1', '2', '3'):
129-
for num in pct_nums1:
130-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
131-
for num in pct_nums2:
132-
test_fmt('', fill, alignment, sign, '', width, '', type, num)
133-
else:
134-
for num in pct_nums1:
135-
test_fmt('', '', '', '', '', '', '1', '%', num)
136-
137-
# We don't currently test a type of '' with floats (see the detailed comment
138-
# in objstr.c)
139-
14036
# tests for errors in format string
14137

14238
try:

tests/float/string_format2.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Change the following to True to get a much more comprehensive set of tests
2+
# to run, albeit, which take considerably longer.
3+
4+
full_tests = False
5+
6+
def test(fmt, *args):
7+
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
8+
9+
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
10+
fmt = '{'
11+
if conv:
12+
fmt += '!'
13+
fmt += conv
14+
fmt += ':'
15+
if alignment:
16+
fmt += fill
17+
fmt += alignment
18+
fmt += sign
19+
fmt += prefix
20+
fmt += width
21+
if precision:
22+
fmt += '.'
23+
fmt += precision
24+
fmt += type
25+
fmt += '}'
26+
test(fmt, arg)
27+
if fill == '0' and alignment == '=':
28+
fmt = '{:'
29+
fmt += sign
30+
fmt += prefix
31+
fmt += width
32+
if precision:
33+
fmt += '.'
34+
fmt += precision
35+
fmt += type
36+
fmt += '}'
37+
test(fmt, arg)
38+
39+
eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0,
40+
-0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10,
41+
1e37, -1e37, 1e-37, -1e-37,
42+
1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0,
43+
1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8,
44+
-1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0,
45+
-1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8)
46+
47+
if full_tests:
48+
for type in ('e', 'E', 'g', 'G', 'n'):
49+
for width in ('', '4', '6', '8', '10'):
50+
for alignment in ('', '<', '>', '=', '^'):
51+
for fill in ('', '@', '0', ' '):
52+
for sign in ('', '+', '-', ' '):
53+
for prec in ('', '1', '3', '6'):
54+
for num in eg_nums:
55+
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
56+
57+
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
58+
# rounds differently than print("%.3f", 1.2345);
59+
60+
f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0,
61+
0.0012, 0.0123, 0.1234, 1.23459, 12.3456,
62+
-0.0001, -0.001, -0.01, -0.1, -1.0, -10.0,
63+
-0.0012, -0.0123, -0.1234, -1.23459, -12.3456)
64+
65+
if full_tests:
66+
for type in ('f', 'F'):
67+
for width in ('', '4', '6', '8', '10'):
68+
for alignment in ('', '<', '>', '=', '^'):
69+
for fill in ('', ' ', '0', '@'):
70+
for sign in ('', '+', '-', ' '):
71+
# An empty precision defaults to 6, but when uPy is
72+
# configured to use a float, we can only use a
73+
# precision of 6 with numbers less than 10 and still
74+
# get results that compare to CPython (which uses
75+
# long doubles).
76+
for prec in ('1', '2', '3'):
77+
for num in f_nums:
78+
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
79+
for num in int_nums2:
80+
test_fmt('', fill, alignment, sign, '', width, '', type, num)
81+
82+
pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99)
83+
pct_nums2 = (True, False, 1, 0, -1)
84+
85+
if full_tests:
86+
type = '%'
87+
for width in ('', '4', '6', '8', '10'):
88+
for alignment in ('', '<', '>', '=', '^'):
89+
for fill in ('', ' ', '0', '@'):
90+
for sign in ('', '+', '-', ' '):
91+
# An empty precision defaults to 6, but when uPy is
92+
# configured to use a float, we can only use a
93+
# precision of 6 with numbers less than 10 and still
94+
# get results that compare to CPython (which uses
95+
# long doubles).
96+
for prec in ('1', '2', '3'):
97+
for num in pct_nums1:
98+
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
99+
for num in pct_nums2:
100+
test_fmt('', fill, alignment, sign, '', width, '', type, num)
101+
else:
102+
for num in pct_nums1:
103+
test_fmt('', '', '', '', '', '', '1', '%', num)
104+
105+
# We don't currently test a type of '' with floats (see the detailed comment
106+
# in objstr.c)

0 commit comments

Comments
 (0)