77 assert_allclose )
88
99from quantecon .markov import gth_solve
10+ import pytest
1011
1112
1213TOL = 1e-15
@@ -90,39 +91,6 @@ def __init__(self):
9091 self .gen_matrix_dicts .append (matrix_dict )
9192
9293
93- def test_stoch_matrix ():
94- """Test with stochastic matrices"""
95- print (__name__ + '.' + test_stoch_matrix .__name__ )
96- matrices = Matrices ()
97- for matrix_dict in matrices .stoch_matrix_dicts :
98- x = gth_solve (matrix_dict ['A' ])
99- yield StationaryDistSumOne (), x
100- yield StationaryDistNonnegative (), x
101- yield StationaryDistEqualToKnown (), matrix_dict ['stationary_dist' ], x
102-
103-
104- def test_kmr_matrix ():
105- """Test with KMR matrices"""
106- print (__name__ + '.' + test_kmr_matrix .__name__ )
107- matrices = Matrices ()
108- for matrix_dict in matrices .kmr_matrix_dicts :
109- x = gth_solve (matrix_dict ['A' ])
110- yield StationaryDistSumOne (), x
111- yield StationaryDistNonnegative (), x
112- yield StationaryDistLeftEigenVec (), matrix_dict ['A' ], x
113-
114-
115- def test_gen_matrix ():
116- """Test with generator matrices"""
117- print (__name__ + '.' + test_gen_matrix .__name__ )
118- matrices = Matrices ()
119- for matrix_dict in matrices .gen_matrix_dicts :
120- x = gth_solve (matrix_dict ['A' ])
121- yield StationaryDistSumOne (), x
122- yield StationaryDistNonnegative (), x
123- yield StationaryDistEqualToKnown (), matrix_dict ['stationary_dist' ], x
124-
125-
12694class AddDescription :
12795 def __init__ (self ):
12896 self .description = self .__class__ .__name__
@@ -148,6 +116,63 @@ def __call__(self, y, x):
148116 assert_allclose (y , x , atol = TOL )
149117
150118
119+ test_classes = [
120+ StationaryDistSumOne ,
121+ StationaryDistNonnegative ,
122+ ]
123+
124+
125+ @pytest .mark .parametrize ("test_class" , test_classes )
126+ def test_stoch_matrix (test_class ):
127+ """Test with stochastic matrices"""
128+ matrices = Matrices ()
129+ for matrix_dict in matrices .stoch_matrix_dicts :
130+ x = gth_solve (matrix_dict ['A' ])
131+ test_class ()(x )
132+
133+
134+ def test_stoch_matrix_1 ():
135+ """Test with stochastic matrices"""
136+ matrices = Matrices ()
137+ for matrix_dict in matrices .stoch_matrix_dicts :
138+ x = gth_solve (matrix_dict ['A' ])
139+ StationaryDistEqualToKnown ()(matrix_dict ['stationary_dist' ], x )
140+
141+
142+ @pytest .mark .parametrize ("test_class" , test_classes )
143+ def test_kmr_matrix (test_class ):
144+ """Test with KMR matrices"""
145+ matrices = Matrices ()
146+ for matrix_dict in matrices .kmr_matrix_dicts :
147+ x = gth_solve (matrix_dict ['A' ])
148+ test_class ()(x )
149+
150+
151+ def test_kmr_matrix_1 ():
152+ """Test with KMR matrices"""
153+ matrices = Matrices ()
154+ for matrix_dict in matrices .kmr_matrix_dicts :
155+ x = gth_solve (matrix_dict ['A' ])
156+ StationaryDistLeftEigenVec ()(matrix_dict ['A' ], x )
157+
158+
159+ @pytest .mark .parametrize ("test_class" , test_classes )
160+ def test_gen_matrix (test_class ):
161+ """Test with generator matrices"""
162+ matrices = Matrices ()
163+ for matrix_dict in matrices .gen_matrix_dicts :
164+ x = gth_solve (matrix_dict ['A' ])
165+ test_class ()(x )
166+
167+
168+ def test_gen_matrix_1 ():
169+ """Test with generator matrices"""
170+ matrices = Matrices ()
171+ for matrix_dict in matrices .gen_matrix_dicts :
172+ x = gth_solve (matrix_dict ['A' ])
173+ StationaryDistEqualToKnown ()(matrix_dict ['stationary_dist' ], x )
174+
175+
151176def test_matrices_with_C_F_orders ():
152177 """
153178 Test matrices with C- and F-contiguous orders
0 commit comments