-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Unittest sample : Proposal for issue #4 #57
Changes from all commits
eabf0a7
e3f02be
538826a
090cd5e
cfe2c5b
6d9c070
cda8f0f
33e4a12
c7d055f
ade1148
60efa3a
5692909
4c542b5
3e0d9b3
7104813
572a442
f097e44
471bdd5
677b3d3
e50d5d1
be420a8
19dc453
54dcdf4
11024a2
c5eae74
a3fd917
f2554cf
3505e1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" | ||
alltest.py : Launch unittests modules in ``testmodules`` list. | ||
|
||
Each test module corresponds to a PARI-GP test file that was ported into a gmpy2 unittest. | ||
""" | ||
import unittest | ||
import sys | ||
from cypari2 import Pari, PariError | ||
|
||
pari = Pari() | ||
|
||
testmodules = [ | ||
'bern', | ||
'bit', | ||
'characteristic', | ||
'charpoly', | ||
'chinese', | ||
'contfrac', | ||
'disc', | ||
'ellmodulareqn', | ||
'factorint', | ||
'galpol', | ||
'idealappr', | ||
'isprime', | ||
'lambert', | ||
'lex', | ||
'lindep', | ||
'linear', | ||
'list', | ||
'log', | ||
'mathnf', | ||
'minim', | ||
'minmax', | ||
'modfun', | ||
'modular', | ||
'nfrootsof1', | ||
'norm', | ||
'number', | ||
'pol', | ||
'prec', | ||
'prime', | ||
'primes', | ||
'qfb', | ||
'qfbclassno', | ||
'qfsolve', | ||
'set', | ||
'subcyclo', | ||
'sumdedekind', | ||
'sumformal', | ||
'zeta' | ||
] | ||
|
||
require_galpol = ["galpol"] | ||
require_seadata = ["ellmodulareqn"] | ||
|
||
galpol_installed = True | ||
seadata_installed = True | ||
|
||
# test extensions presence. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would propose to encapsulate these in functions |
||
try: | ||
pari.ellmodulareqn(2) | ||
except PariError as e: | ||
if "error opening seadata file" in str(e): | ||
seadata_installed = False | ||
else: | ||
raise e | ||
|
||
try: | ||
pari.galoisgetpol(8) | ||
except PariError as e: | ||
if "error opening galpol file" in str(e): | ||
galpol_installed = False | ||
else: | ||
raise e | ||
|
||
suite = unittest.TestSuite() | ||
|
||
|
||
for t in testmodules: | ||
if (galpol_installed or t not in require_galpol) and (seadata_installed or t not in require_seadata): | ||
# Load all the test cases from the module. | ||
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(t)) | ||
|
||
res = unittest.TextTestRunner().run(suite) | ||
retcode = 0 if res.wasSuccessful() else 1 | ||
sys.exit(retcode) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Original pari/GP test file bern : | ||
bernfrac(0); | ||
bernfrac(1); | ||
for(k = 1, 20, print(bernfrac(k))); | ||
for(k = 0, 5, print(bernpol(k))); | ||
bernfrac(-1) | ||
bernreal(-1) | ||
bernpol(-1) | ||
bernvec(30) | ||
""" | ||
import unittest | ||
from cypari2 import Pari, PariError | ||
|
||
pari = Pari() | ||
|
||
|
||
class TestBern(unittest.TestCase): | ||
def test_bern(self): | ||
pari.bernfrac(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what this is supposed to test? and why keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It test that it doesn't crash. I keep them mainly to stick with the original GP test file. I keep |
||
pari.bernfrac(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||
|
||
t = ('-1/2', '1/6', '0', '-1/30', '0', '1/42', '0', '-1/30', '0', '5/66', '0', '-691/2730', | ||
'0', '7/6', '0', '-3617/510', '0', '43867/798', '0', '-174611/330') | ||
for k in range(1, 21): | ||
self.assertEquals(pari.bernfrac(k), t[k-1]) | ||
|
||
t = ('1', 'x - 1/2', 'x^2 - x + 1/6', 'x^3 - 3/2*x^2 + 1/2*x', 'x^4 - 2*x^3 + x^2 - 1/30', | ||
'x^5 - 5/2*x^4 + 5/3*x^3 - 1/6*x') | ||
for k in range(0, 6): | ||
self.assertEquals(pari.bernpol(k), t[k]) | ||
|
||
with self.assertRaises(PariError) as context: | ||
pari.bernfrac(-1) | ||
self.assertTrue('domain error in bernfrac: index < 0' in str(context.exception)) | ||
|
||
with self.assertRaises(PariError) as context: | ||
pari.bernreal(-1) | ||
self.assertTrue('domain error in bernreal: index < 0' in str(context.exception)) | ||
|
||
with self.assertRaises(PariError) as context: | ||
pari.bernpol(-1) | ||
|
||
self.assertTrue('domain error in bernpol: index < 0' in str(context.exception)) | ||
|
||
def test_bernvec(self): | ||
self.assertEquals(pari.bernvec(30), '[1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6, -3617/510, 43867/798,' + | ||
' -174611/330, 854513/138, -236364091/2730, 8553103/6, -23749461029/870, 8615841276005/1432' + | ||
'2, -7709321041217/510, 2577687858367/6, -26315271553053477373/1919190, 2929993913841559/6,' + | ||
' -261082718496449122051/13530, 1520097643918070802691/1806, -27833269579301024235023/690, ' + | ||
'596451111593912163277961/282, -5609403368997817686249127547/46410, 49505720524107964821247' + | ||
'7525/66, -801165718135489957347924991853/1590, 29149963634884862421418123812691/798, -2479' + | ||
'392929313226753685415739663229/870, 84483613348880041862046775994036021/354, -121523314048' + | ||
'3755572040304994079820246041491/56786730]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should briefly document the mechanic of the tests here.