Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
d4315a6c
Commit
d4315a6c
authored
9 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
float/string_format: Split large test in 2.
parent
2850e7cd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/float/string_format.py
+0
-104
0 additions, 104 deletions
tests/float/string_format.py
tests/float/string_format2.py
+106
-0
106 additions, 0 deletions
tests/float/string_format2.py
with
106 additions
and
104 deletions
tests/float/string_format.py
+
0
−
104
View file @
d4315a6c
# Change the following to True to get a much more comprehensive set of tests
# to run, albeit, which take considerably longer.
full_tests
=
False
def
test
(
fmt
,
*
args
):
def
test
(
fmt
,
*
args
):
print
(
'
{:8s}
'
.
format
(
fmt
)
+
'
>
'
+
fmt
.
format
(
*
args
)
+
'
<
'
)
print
(
'
{:8s}
'
.
format
(
fmt
)
+
'
>
'
+
fmt
.
format
(
*
args
)
+
'
<
'
)
...
@@ -38,105 +33,6 @@ print("%.0f" % (1.750000 % 0.08333333333))
...
@@ -38,105 +33,6 @@ print("%.0f" % (1.750000 % 0.08333333333))
#print("%.2f" % (1.750000 % 0.08333333333))
#print("%.2f" % (1.750000 % 0.08333333333))
#print("%.12f" % (1.750000 % 0.08333333333))
#print("%.12f" % (1.750000 % 0.08333333333))
def
test_fmt
(
conv
,
fill
,
alignment
,
sign
,
prefix
,
width
,
precision
,
type
,
arg
):
fmt
=
'
{
'
if
conv
:
fmt
+=
'
!
'
fmt
+=
conv
fmt
+=
'
:
'
if
alignment
:
fmt
+=
fill
fmt
+=
alignment
fmt
+=
sign
fmt
+=
prefix
fmt
+=
width
if
precision
:
fmt
+=
'
.
'
fmt
+=
precision
fmt
+=
type
fmt
+=
'
}
'
test
(
fmt
,
arg
)
if
fill
==
'
0
'
and
alignment
==
'
=
'
:
fmt
=
'
{:
'
fmt
+=
sign
fmt
+=
prefix
fmt
+=
width
if
precision
:
fmt
+=
'
.
'
fmt
+=
precision
fmt
+=
type
fmt
+=
'
}
'
test
(
fmt
,
arg
)
eg_nums
=
(
0.0
,
-
0.0
,
0.1
,
1.234
,
12.3459
,
1.23456789
,
123456789.0
,
-
0.0
,
-
0.1
,
-
1.234
,
-
12.3459
,
1e4
,
1e-4
,
1e5
,
1e-5
,
1e6
,
1e-6
,
1e10
,
1e37
,
-
1e37
,
1e-37
,
-
1e-37
,
1.23456e8
,
1.23456e7
,
1.23456e6
,
1.23456e5
,
1.23456e4
,
1.23456e3
,
1.23456e2
,
1.23456e1
,
1.23456e0
,
1.23456e-1
,
1.23456e-2
,
1.23456e-3
,
1.23456e-4
,
1.23456e-5
,
1.23456e-6
,
1.23456e-7
,
1.23456e-8
,
-
1.23456e8
,
-
1.23456e7
,
-
1.23456e6
,
-
1.23456e5
,
-
1.23456e4
,
-
1.23456e3
,
-
1.23456e2
,
-
1.23456e1
,
-
1.23456e0
,
-
1.23456e-1
,
-
1.23456e-2
,
-
1.23456e-3
,
-
1.23456e-4
,
-
1.23456e-5
,
-
1.23456e-6
,
-
1.23456e-7
,
-
1.23456e-8
)
if
full_tests
:
for
type
in
(
'
e
'
,
'
E
'
,
'
g
'
,
'
G
'
,
'
n
'
):
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
@
'
,
'
0
'
,
'
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
for
prec
in
(
''
,
'
1
'
,
'
3
'
,
'
6
'
):
for
num
in
eg_nums
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
# rounds differently than print("%.3f", 1.2345);
f_nums
=
(
0.0
,
-
0.0
,
0.0001
,
0.001
,
0.01
,
0.1
,
1.0
,
10.0
,
0.0012
,
0.0123
,
0.1234
,
1.23459
,
12.3456
,
-
0.0001
,
-
0.001
,
-
0.01
,
-
0.1
,
-
1.0
,
-
10.0
,
-
0.0012
,
-
0.0123
,
-
0.1234
,
-
1.23459
,
-
12.3456
)
if
full_tests
:
for
type
in
(
'
f
'
,
'
F
'
):
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
'
,
'
0
'
,
'
@
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
for
prec
in
(
'
1
'
,
'
2
'
,
'
3
'
):
for
num
in
f_nums
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
for
num
in
int_nums2
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
''
,
type
,
num
)
pct_nums1
=
(
0.1
,
0.58
,
0.99
,
-
0.1
,
-
0.58
,
-
0.99
)
pct_nums2
=
(
True
,
False
,
1
,
0
,
-
1
)
if
full_tests
:
type
=
'
%
'
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
'
,
'
0
'
,
'
@
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
for
prec
in
(
'
1
'
,
'
2
'
,
'
3
'
):
for
num
in
pct_nums1
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
for
num
in
pct_nums2
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
''
,
type
,
num
)
else
:
for
num
in
pct_nums1
:
test_fmt
(
''
,
''
,
''
,
''
,
''
,
''
,
'
1
'
,
'
%
'
,
num
)
# We don't currently test a type of '' with floats (see the detailed comment
# in objstr.c)
# tests for errors in format string
# tests for errors in format string
try
:
try
:
...
...
This diff is collapsed.
Click to expand it.
tests/float/string_format2.py
0 → 100644
+
106
−
0
View file @
d4315a6c
# Change the following to True to get a much more comprehensive set of tests
# to run, albeit, which take considerably longer.
full_tests
=
False
def
test
(
fmt
,
*
args
):
print
(
'
{:8s}
'
.
format
(
fmt
)
+
'
>
'
+
fmt
.
format
(
*
args
)
+
'
<
'
)
def
test_fmt
(
conv
,
fill
,
alignment
,
sign
,
prefix
,
width
,
precision
,
type
,
arg
):
fmt
=
'
{
'
if
conv
:
fmt
+=
'
!
'
fmt
+=
conv
fmt
+=
'
:
'
if
alignment
:
fmt
+=
fill
fmt
+=
alignment
fmt
+=
sign
fmt
+=
prefix
fmt
+=
width
if
precision
:
fmt
+=
'
.
'
fmt
+=
precision
fmt
+=
type
fmt
+=
'
}
'
test
(
fmt
,
arg
)
if
fill
==
'
0
'
and
alignment
==
'
=
'
:
fmt
=
'
{:
'
fmt
+=
sign
fmt
+=
prefix
fmt
+=
width
if
precision
:
fmt
+=
'
.
'
fmt
+=
precision
fmt
+=
type
fmt
+=
'
}
'
test
(
fmt
,
arg
)
eg_nums
=
(
0.0
,
-
0.0
,
0.1
,
1.234
,
12.3459
,
1.23456789
,
123456789.0
,
-
0.0
,
-
0.1
,
-
1.234
,
-
12.3459
,
1e4
,
1e-4
,
1e5
,
1e-5
,
1e6
,
1e-6
,
1e10
,
1e37
,
-
1e37
,
1e-37
,
-
1e-37
,
1.23456e8
,
1.23456e7
,
1.23456e6
,
1.23456e5
,
1.23456e4
,
1.23456e3
,
1.23456e2
,
1.23456e1
,
1.23456e0
,
1.23456e-1
,
1.23456e-2
,
1.23456e-3
,
1.23456e-4
,
1.23456e-5
,
1.23456e-6
,
1.23456e-7
,
1.23456e-8
,
-
1.23456e8
,
-
1.23456e7
,
-
1.23456e6
,
-
1.23456e5
,
-
1.23456e4
,
-
1.23456e3
,
-
1.23456e2
,
-
1.23456e1
,
-
1.23456e0
,
-
1.23456e-1
,
-
1.23456e-2
,
-
1.23456e-3
,
-
1.23456e-4
,
-
1.23456e-5
,
-
1.23456e-6
,
-
1.23456e-7
,
-
1.23456e-8
)
if
full_tests
:
for
type
in
(
'
e
'
,
'
E
'
,
'
g
'
,
'
G
'
,
'
n
'
):
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
@
'
,
'
0
'
,
'
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
for
prec
in
(
''
,
'
1
'
,
'
3
'
,
'
6
'
):
for
num
in
eg_nums
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
# rounds differently than print("%.3f", 1.2345);
f_nums
=
(
0.0
,
-
0.0
,
0.0001
,
0.001
,
0.01
,
0.1
,
1.0
,
10.0
,
0.0012
,
0.0123
,
0.1234
,
1.23459
,
12.3456
,
-
0.0001
,
-
0.001
,
-
0.01
,
-
0.1
,
-
1.0
,
-
10.0
,
-
0.0012
,
-
0.0123
,
-
0.1234
,
-
1.23459
,
-
12.3456
)
if
full_tests
:
for
type
in
(
'
f
'
,
'
F
'
):
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
'
,
'
0
'
,
'
@
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
for
prec
in
(
'
1
'
,
'
2
'
,
'
3
'
):
for
num
in
f_nums
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
for
num
in
int_nums2
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
''
,
type
,
num
)
pct_nums1
=
(
0.1
,
0.58
,
0.99
,
-
0.1
,
-
0.58
,
-
0.99
)
pct_nums2
=
(
True
,
False
,
1
,
0
,
-
1
)
if
full_tests
:
type
=
'
%
'
for
width
in
(
''
,
'
4
'
,
'
6
'
,
'
8
'
,
'
10
'
):
for
alignment
in
(
''
,
'
<
'
,
'
>
'
,
'
=
'
,
'
^
'
):
for
fill
in
(
''
,
'
'
,
'
0
'
,
'
@
'
):
for
sign
in
(
''
,
'
+
'
,
'
-
'
,
'
'
):
# An empty precision defaults to 6, but when uPy is
# configured to use a float, we can only use a
# precision of 6 with numbers less than 10 and still
# get results that compare to CPython (which uses
# long doubles).
for
prec
in
(
'
1
'
,
'
2
'
,
'
3
'
):
for
num
in
pct_nums1
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
prec
,
type
,
num
)
for
num
in
pct_nums2
:
test_fmt
(
''
,
fill
,
alignment
,
sign
,
''
,
width
,
''
,
type
,
num
)
else
:
for
num
in
pct_nums1
:
test_fmt
(
''
,
''
,
''
,
''
,
''
,
''
,
'
1
'
,
'
%
'
,
num
)
# We don't currently test a type of '' with floats (see the detailed comment
# in objstr.c)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment