From 79d8219c4ac2ce7972247f3e7690e776295fabba Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 1 Nov 2016 18:58:18 -0400 Subject: [PATCH] Add more doctest examples to the randomgen module. --- test/__init__.py | 2 +- test/randomgen.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/test/__init__.py b/test/__init__.py index 074b2b1..0f6f15c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -28,7 +28,7 @@ def build_suite(): suite.addTest(DocTestSuite(games, optionflags=ELLIPSIS)) suite.addTest(DocTestSuite(matrices, optionflags=ELLIPSIS)) suite.addTest(DocTestSuite(symmetric_linear_game_test)) - suite.addTest(DocTestSuite(randomgen)) + suite.addTest(DocTestSuite(randomgen, optionflags=ELLIPSIS)) slg_tests = TestLoader().loadTestsFromModule(symmetric_linear_game_test) suite.addTest(slg_tests) mat_tests = TestLoader().loadTestsFromModule(matrices_test) diff --git a/test/randomgen.py b/test/randomgen.py index 395408c..9510c04 100644 --- a/test/randomgen.py +++ b/test/randomgen.py @@ -314,6 +314,12 @@ def random_orthant_game(): SymmetricLinearGame A random game over some nonnegative orthant. + Examples + -------- + + >>> random_orthant_game() + + """ ambient_dim = random_natural() + 1 K = NonnegativeOrthant(ambient_dim) @@ -343,6 +349,12 @@ def random_icecream_game(): SymmetricLinearGame A random game over some ice-cream cone. + Examples + -------- + + >>> random_icecream_game() + + """ # Use a minimum dimension of two to avoid divide-by-zero in # the fudge factor we make up later. @@ -387,6 +399,12 @@ def random_ll_orthant_game(): A random game over some nonnegative orthant whose ``payoff`` method is based on a Lyapunov-like ``L`` operator. + Examples + -------- + + >>> random_ll_orthant_game() + + """ G = random_orthant_game() L = random_diagonal_matrix(G._K.dimension()) @@ -419,6 +437,12 @@ def random_ll_icecream_game(): A random game over some ice-cream cone whose ``payoff`` method is based on a Lyapunov-like ``L`` operator. + Examples + -------- + + >>> random_ll_icecream_game() + + """ G = random_icecream_game() L = random_lyapunov_like_icecream(G._K.dimension()) @@ -452,6 +476,12 @@ def random_positive_orthant_game(): A random game over some nonnegative orthant whose ``payoff`` method is based on a positive ``L`` operator. + Examples + -------- + + >>> random_positive_orthant_game() + + """ G = random_orthant_game() @@ -487,6 +517,22 @@ def random_nn_scaling(G): (float, SymmetricLinearGame) A pair containing the both the scaling factor and the new scaled game. + Examples + -------- + + >>> from dunshire.matrices import norm + >>> from dunshire.options import ABS_TOL + >>> G = random_orthant_game() + >>> (alpha, H) = random_nn_scaling(G) + >>> alpha >= 0 + True + >>> G._K == H._K + True + >>> norm(G._e1 - H._e1) < ABS_TOL + True + >>> norm(G._e2 - H._e2) < ABS_TOL + True + """ alpha = random_nn_scalar() H = SymmetricLinearGame(alpha*G._L.trans(), G._K, G._e1, G._e2) @@ -518,6 +564,20 @@ def random_translation(G): A pair containing the both the translation distance and the new scaled game. + Examples + -------- + + >>> from dunshire.matrices import norm + >>> from dunshire.options import ABS_TOL + >>> G = random_orthant_game() + >>> (alpha, H) = random_translation(G) + >>> G._K == H._K + True + >>> norm(G._e1 - H._e1) < ABS_TOL + True + >>> norm(G._e2 - H._e2) < ABS_TOL + True + """ alpha = random_scalar() tensor_prod = G._e1 * G._e2.trans() -- 2.44.2