test_hp_space.py 1.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Theo Steininger's avatar
Theo Steininger committed
13
#
14
# Copyright(C) 2013-2019 Max-Planck-Society
Theo Steininger's avatar
Theo Steininger committed
15
#
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
17

Jait Dixit's avatar
Jait Dixit committed
18
import numpy as np
Philipp Arras's avatar
Philipp Arras committed
19
import pytest
20
21
from numpy.testing import assert_almost_equal, assert_equal, assert_raises

Philipp Arras's avatar
Philipp Arras committed
22
from nifty8 import HPSpace, myassert
Jait Dixit's avatar
Jait Dixit committed
23

24
from ..common import setup_function, teardown_function
Philipp Arras's avatar
Philipp Arras committed
25
26

pmp = pytest.mark.parametrize
Martin Reinecke's avatar
Martin Reinecke committed
27
# [nside, expected]
Philipp Arras's avatar
Philipp Arras committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
CONSTRUCTOR_CONFIGS = [[
    2, {
        'nside': 2,
        'harmonic': False,
        'shape': (48,),
        'size': 48,
    }
], [5, {
    'nside': 5,
    'harmonic': False,
    'shape': (300,),
    'size': 300,
}], [1, {
    'nside': 1,
    'harmonic': False,
    'shape': (12,),
    'size': 12,
}], [0, {
    'error': ValueError
}]]

Jait Dixit's avatar
Jait Dixit committed
49

Philipp Arras's avatar
Philipp Arras committed
50
51
def test_property_ret_type():
    x = HPSpace(2)
52
    myassert(isinstance(getattr(x, 'nside'), int))
Jait Dixit's avatar
Jait Dixit committed
53
54


Philipp Arras's avatar
Philipp Arras committed
55
56
57
58
59
60
61
62
63
@pmp('nside, expected', CONSTRUCTOR_CONFIGS)
def test_constructor(nside, expected):
    if 'error' in expected:
        with assert_raises(expected['error']):
            HPSpace(nside)
    else:
        h = HPSpace(nside)
        for key, value in expected.items():
            assert_equal(getattr(h, key), value)
Jait Dixit's avatar
Jait Dixit committed
64
65


Philipp Arras's avatar
Philipp Arras committed
66
67
def test_dvol():
    assert_almost_equal(HPSpace(2).dvol, np.pi/12)