Commit bfccdea3 authored by Roel Aaij's avatar Roel Aaij
Browse files

Add some python tests

parent ad5ad185
%% Cell type:code id: tags:
``` python
import numpy as np
import KM3NeT-bkg-gen as xt
from IPython.display import display
```
%% Cell type:markdown id: tags:
### Function example1
%% Cell type:code id: tags:
``` python
print(xt.example1.__doc__)
```
%% Output
example1(arg0: numpy.ndarray[float]) -> float
Return the first element of an array, of dimension at least one
%% Cell type:code id: tags:
``` python
a = np.arange(15).reshape(3, 5) + 5
b = xt.example1(a)
display(a)
display(b)
```
%% Output
%% Cell type:markdown id: tags:
### Function example2
%% Cell type:code id: tags:
``` python
print(xt.example2.__doc__)
```
%% Output
example2(arg0: numpy.ndarray[float]) -> numpy.ndarray[float]
Return the the specified array plus 2
%% Cell type:code id: tags:
``` python
a = np.arange(15).reshape(3, 5)
b = xt.example2(a)
display(a)
display(b)
```
%% Output
%% Cell type:markdown id: tags:
### Function readme_example1
%% Cell type:code id: tags:
``` python
print(xt.readme_example1.__doc__)
```
%% Output
readme_example1(arg0: numpy.ndarray[float]) -> float
Accumulate the sines of all the values of the specified array
%% Cell type:code id: tags:
``` python
PI = np.pi
a = np.linspace(0, PI, 100)
b = xt.readme_example1(a)
display(a)
display(np.sin(a).sum())
display(b)
```
%% Output
%% Cell type:markdown id: tags:
### Function vectorize_example1
%% Cell type:code id: tags:
``` python
print(xt.vectorize_example1.__doc__)
```
%% Output
vectorize_example1(arg0: numpy.ndarray[float], arg1: numpy.ndarray[float]) -> numpy.ndarray[float]
Add the sine and and cosine of the two specified values
%% Cell type:code id: tags:
``` python
PI = np.pi
a = np.linspace(0, PI, 10)
b = np.linspace(0, 2*PI, 10)
c = xt.vectorize_example1(a, b)
d = np.sin(a)+np.cos(b)
display(a)
display(b)
display(c)
display(np.isclose(c, d))
```
%% Output
[pytest]
addopts = --verbose
python_files = tests/python/*.py
testpaths = tests
norecursedirs = .git build
[aliases]
test = pytest
......@@ -77,11 +77,13 @@ setup(
version=__version__,
author='Roel Aaij',
author_email='roelaaij@nikhef.nl',
url='https://sikkel.nikhef.nl/roelaaij/generate_and_sort',
url='https://sikkel.nikhef.nl/roelaaij/k40gen',
description='standalone background generator for KM3NeT',
long_description='',
ext_modules=ext_modules,
install_requires=['numpy', 'cmake'],
setup_requires=['pytest-runner', 'numpy', 'cmake'],
install_requires=['numpy'],
tests_require=["pytest"],
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
)
import k40gen as m
from unittest import TestCase
import numpy as np
def generate():
import k40gen as m
gens = m.Generators(21341, 1245, [7000., 700., 70., 0.])
times = m.generate_k40(0, int(1e8), gens, False)
assert(times.shape[0] == 4)
class K40GenTest(TestCase):
def generate(self):
# v = np.arange(15).reshape(3, 5)
# y = m.readme_example1(v)
# np.testing.assert_allclose(y, 1.2853996391883833, 1e-12)
return True
def test_generate():
generate()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment