2
Test functions for models.utils
6
import numpy.random as R
7
from numpy.testing import *
9
from models import utils
11
class TestUtils(TestCase):
13
def test_recipr(self):
14
X = np.array([[2,1],[-1,0]])
16
assert_almost_equal(Y, np.array([[0.5,1],[0,0]]))
18
def test_recipr0(self):
19
X = np.array([[2,1],[-4,0]])
21
assert_almost_equal(Y, np.array([[0.5,1],[-0.25,0]]))
24
X = R.standard_normal((40,10))
25
self.assertEquals(utils.rank(X), 10)
27
X[:,0] = X[:,1] + X[:,2]
28
self.assertEquals(utils.rank(X), 9)
30
def test_fullrank(self):
31
X = R.standard_normal((40,10))
32
X[:,0] = X[:,1] + X[:,2]
35
self.assertEquals(Y.shape, (40,9))
36
self.assertEquals(utils.rank(Y), 9)
38
X[:,5] = X[:,3] + X[:,4]
40
self.assertEquals(Y.shape, (40,8))
41
self.assertEquals(utils.rank(Y), 8)
43
def test_StepFunction(self):
46
f = utils.StepFunction(x, y)
47
assert_almost_equal(f( np.array([[3.2,4.5],[24,-3.1]]) ), [[ 3, 4], [19, 0]])
49
def test_StepFunctionBadShape(self):
52
self.assertRaises(ValueError, utils.StepFunction, x, y)
55
self.assertRaises(ValueError, utils.StepFunction, x, y)