Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix root_of_unity warning and doctests errors. When mpc version != 1.0.0 #231

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gmpy2_mpc_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ extern "C" {
static PyObject * GMPy_Complex_Phase(PyObject *x, CTXT_Object *context);
static PyObject * GMPy_Context_Phase(PyObject *self, PyObject *other);

#ifdef MPC_110
static PyObject * GMPy_Complex_Root_Of_Unity(PyObject *n, PyObject *k, CTXT_Object *context);
static PyObject * GMPy_Context_Root_Of_Unity(PyObject *self, PyObject *args);
#endif

static PyObject * GMPy_Complex_Norm(PyObject *x, CTXT_Object *context);
static PyObject * GMPy_Context_Norm(PyObject *self, PyObject *other);
Expand Down
22 changes: 21 additions & 1 deletion test/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import glob
import doctest
from doctest import DocTestParser, Example, SKIP
import gmpy2

# *****************************************************************************
Expand Down Expand Up @@ -42,6 +43,24 @@
else:
repeat = 1

# If mpc version < 1.1.0 gmpy2.root_of_unity may not be defined.
# We create a doctest flag to skip a doctest if root_of_unity is not defined
SKIP_NO_ROOT_OF_UNITY = doctest.register_optionflag("SKIP_NO_ROOT_OF_UNITY")
has_root_of_unity = 'root_of_unity' in dir(gmpy2)

class Gmpy2DocTestParser(DocTestParser):
def parse(self, *args, **kwargs):
examples = DocTestParser.parse(self, *args, **kwargs)
for example in examples:
if not isinstance(example, Example):
continue
if not has_root_of_unity and SKIP_NO_ROOT_OF_UNITY in example.options:
example.options[SKIP] = True

return examples

parser = Gmpy2DocTestParser()

print()
print("Unit tests for gmpy2 {0} with Python {1}".format(gmpy2.version(), sys.version.split()[0]))
print(" Mutliple-precision library: {0}".format(gmpy2.mp_version()))
Expand Down Expand Up @@ -105,7 +124,8 @@
result = doctest.testfile(test, globs=globals(),
optionflags=doctest.IGNORE_EXCEPTION_DETAIL |
doctest.NORMALIZE_WHITESPACE |
doctest.REPORT_NDIFF)
doctest.REPORT_NDIFF,
parser=parser)
print("Results for: {0:25}".format(test.split(".")[0]), end="")
print(" Attempted: {1:4d} Failed: {0:4d}".format(*result), end="")
if debug:
Expand Down
18 changes: 9 additions & 9 deletions test/test_mpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,25 @@ mpfr('0.89605538457134393')

Test root_of_unity
------------------
>>> gmpy2.root_of_unity(1,1)
>>> gmpy2.root_of_unity(1,1) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('1.0+0.0j')
>>> gmpy2.root_of_unity(1,2)
>>> gmpy2.root_of_unity(1,2) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('1.0+0.0j')
>>> gmpy2.root_of_unity(2,1)
>>> gmpy2.root_of_unity(2,1) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('-1.0+0.0j')
>>> gmpy2.root_of_unity(3,1)
>>> gmpy2.root_of_unity(3,1) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('-0.5+0.8660254037844386j')
>>> gmpy2.root_of_unity(3,2)
>>> gmpy2.root_of_unity(3,2) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('-0.5-0.8660254037844386j')
>>> gmpy2.root_of_unity(3,3)
>>> gmpy2.root_of_unity(3,3) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('1.0+0.0j')
>>> gmpy2.ieee(128).root_of_unity(3,1)
>>> gmpy2.ieee(128).root_of_unity(3,1) # doctest: +SKIP_NO_ROOT_OF_UNITY
mpc('-0.5+0.866025403784438646763723170752936161j',(113,113))
>>> gmpy2.ieee(128).root_of_unity()
>>> gmpy2.ieee(128).root_of_unity() # doctest: +SKIP_NO_ROOT_OF_UNITY
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: root_of_unity() requires 2 arguments
>>> gmpy2.ieee(128).root_of_unity('a','b')
>>> gmpy2.ieee(128).root_of_unity('a','b') # doctest: +SKIP_NO_ROOT_OF_UNITY
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: root_of_unity() requires integer arguments
Expand Down