test_nifty_utilities.py 2.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
# -*- coding: utf-8 -*-

import numpy as np
from numpy.testing import assert_equal,\
    assert_almost_equal,\
    assert_raises

from nose_parameterized import parameterized
import unittest

from nifty.nifty_utilities import hermitianize,\
    _hermitianize_inverter

theos's avatar
theos committed
14
15
16
from nifty.d2o import distributed_data_object,\
                      STRATEGIES

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
###############################################################################

def custom_name_func(testcase_func, param_num, param):
    return "%s_%s" % (
        testcase_func.__name__,
        parameterized.to_safe_name("_".join(str(x) for x in param.args)),
    )

###############################################################################

test_data = np.array([[-10,   9,  10,   2,  -7,  -8],
                      [ -5,   5,   5,  -1,   9,   3],
                      [ -2,  -2,   8,   9,   9, -10],
                      [ -8,  -5,  -2, -10,  -7,   7],
                      [ 10,   6,  -2,   6,  -3,  -1],
                      [  8,   1,  10,  -7,   6,  -6]])

flipped_data = np.array([[-10,  -8,  -7,   2,  10,   9],
                      [  8,  -6,   6,  -7,  10,   1],
                      [ 10,  -1,  -3,   6,  -2,   6],
                      [ -8,   7,  -7, -10,  -2,  -5],
                      [ -2, -10,   9,   9,   8,  -2],
                      [ -5,   3,   9,  -1,   5,   5]])

###############################################################################
###############################################################################

class Test_hermitianize_inverter(unittest.TestCase):
    def test_with_ndarray(self):
theos's avatar
theos committed
46
47
       assert_equal(_hermitianize_inverter(test_data), flipped_data)

48
    @parameterized.expand(STRATEGIES['global'],
theos's avatar
theos committed
49
                          testcase_func_name=custom_name_func)
50
51
    def test_with_d2o(self, distribution_strategy):
        d = distributed_data_object(
theos's avatar
theos committed
52
                                test_data,
53
54
                                distribution_strategy=distribution_strategy)
        assert_equal(_hermitianize_inverter(d).get_full_data(), flipped_data)