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

Unittest sample : Proposal for issue #4 #57

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eabf0a7
Initial tests units
Sep 26, 2017
e3f02be
functions utils for test units
Sep 26, 2017
538826a
Add test of linear group
Sep 26, 2017
090cd5e
Add tests for several files
Sep 29, 2017
cfe2c5b
add number and pol testunits
Oct 2, 2017
6d9c070
Add tests for several files:
Oct 3, 2017
cda8f0f
corrections de test
Oct 3, 2017
33e4a12
Add tests for several files:
Oct 5, 2017
c7d055f
isprime : use ** operator instead of int(pow(x))
Oct 12, 2017
ade1148
unittest polred
Oct 12, 2017
60efa3a
unittest Add polred file in alltest
Oct 12, 2017
5692909
unittest : add bit test file
Oct 13, 2017
4c542b5
unittest : add charpoly test file
Oct 13, 2017
3e0d9b3
Unittest replace call precision=127 by precision=128
Oct 18, 2017
7104813
number.py
Nov 9, 2017
572a442
add unittest to the 'make check' command
Nov 9, 2017
f097e44
alltest.py set return code to 1 if faillures in test suite
Nov 9, 2017
471bdd5
alltest.py run a test unit only if his required extension
Nov 10, 2017
677b3d3
alltest.py run a test unit only if his required extension
Nov 10, 2017
e50d5d1
To squash
Nov 10, 2017
be420a8
testutils : xrange compatibility for python3
Nov 10, 2017
19dc453
unittests : Compatibility with python3
Nov 13, 2017
54dcdf4
unittests : remove tests not working with snapshots version of gap
Nov 15, 2017
11024a2
unittests : remove tests not working with 2.8.1.beta version of gap
Jan 17, 2018
c5eae74
unittests : Build a sample branch with only fully working tests
Jan 17, 2018
a3fd917
unittests : remove unittest_template file
Jan 17, 2018
f2554cf
unittests : Enhance alltest.py
Jan 18, 2018
3505e1d
unittests : Remove comments from tests_generator.py
Jan 18, 2018
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install:

check:
$(PYTHON) tests/rundoctest.py
$(PYTHON) tests/unittests/alltest.py

dist:
chmod go+rX-w -R .
Expand Down
86 changes: 86 additions & 0 deletions tests/unittests/alltest.py
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
Copy link
Collaborator

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.

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to encapsulate these in functions has_seadata, has_galpol, has_elldata, etc that would actually be part of the cypari2 library. Perhaps as methods of Pari.

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)
55 changes: 55 additions & 0 deletions tests/unittests/bern.py
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this is supposed to test? and why keeping ;?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ; during developement as an help to associate results with the corresponding test.
Keeping them after can has no sense. I will remove them.

pari.bernfrac(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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]')
Loading