This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add complex case to test_builtin abs()
Type: Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Evelyn Mitchell, Sergey.Kirpichev, mark.dickinson, ned.deily
Priority: low Keywords:

Created on 2016-08-14 19:32 by Evelyn Mitchell, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg272688 - (view) Author: Evelyn Mitchell (Evelyn Mitchell) * (Python triager) Date: 2016-08-14 19:32
The description of abs() says "If the argument is a complex number, its magnitude is returned." but test_builtin doesn't include any complex number test cases.
msg272689 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-08-14 19:48
I think tests for abs() using complex numbers are already in test_cmath.  How do they look?
msg272690 - (view) Author: Evelyn Mitchell (Evelyn Mitchell) * (Python triager) Date: 2016-08-14 20:02
test_cmath includes abs() of zeros, infinities, and real or imaginary part
NaN, but does not include a test for the magnitude conversion, which would
be triggered by something like
>>> abs(complex(2.1,3.5))
4.08166632639171
>>> abs(complex('2.1+3.5j'))
4.08166632639171

And in looking through test_cmath, it appears that only the two numeric
argument form of complex(i, j) is tested for any of the functions, not the
complex('i+nj') string form.

On Sun, Aug 14, 2016 at 1:48 PM, Ned Deily <report@bugs.python.org> wrote:

>
> Ned Deily added the comment:
>
> I think tests for abs() using complex numbers are already in test_cmath.
> How do they look?
>
> ----------
> nosy: +ned.deily
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue27763>
> _______________________________________
>
msg272748 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2016-08-15 11:02
> in looking through test_cmath, it appears that only the two numeric
> argument form of complex(i, j) is tested for any of the functions, not the
> complex('i+nj') string form.

We're testing the cmath functions on complex number inputs; I don't think it matters much how those complex numbers are created. The string form of the constructor can't create any complex numbers that the two-argument `complex(x, y)` form can't, so we're not losing test coverage by only using the `complex(x, y)` form.

The complex number creation from both strings and pairs of floats should be tested independently, of course.
msg391576 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-04-22 05:13
> We're testing the cmath functions on complex number inputs

Indeed.  Also, for abs(complex) - there is test_abs() in the test_complex.py.

> The complex number creation from both strings and pairs of floats should be tested independently, of course.

It seems, there are such tests as well.  E.g. test_constructor() in the same file.

Mark, perhaps this can be closed?
msg391581 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-04-22 08:20
Yes, it looks as though we do have tests of the form that Evelyn describes in test_complex (which also seems like the right place for those tests).

Closing here. Thanks Sergey for the ping!
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71950
2021-04-22 08:20:42mark.dickinsonsetresolution: out of date
2021-04-22 08:20:20mark.dickinsonsetstatus: open -> closed

messages: + msg391581
stage: test needed -> resolved
2021-04-22 05:13:45Sergey.Kirpichevsetnosy: + Sergey.Kirpichev
messages: + msg391576
2016-08-15 11:02:29mark.dickinsonsetnosy: + mark.dickinson
messages: + msg272748
2016-08-14 20:02:07Evelyn Mitchellsetmessages: + msg272690
2016-08-14 19:48:03ned.deilysetnosy: + ned.deily
messages: + msg272689
2016-08-14 19:32:52Evelyn Mitchellcreate