]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - test/matrices_test.py
A bunch more doc fixes.
[dunshire.git] / test / matrices_test.py
index ce57c7dc32a845b38af4dbad75e362c9e1da9b6f..69f9da906e16462423d4a922e420046125ffef04 100644 (file)
@@ -1,8 +1,8 @@
 """
-Unit tests for the functions in the ``matrices`` module.
+Unit tests for the functions in the :mod:`dunshire.matrices` module.
 """
 
-from copy import copy
+from copy import deepcopy
 from unittest import TestCase
 
 from dunshire.matrices import (append_col, append_row, condition_number,
@@ -36,7 +36,7 @@ class AppendColTest(TestCase):
 
 class AppendRowTest(TestCase):
     """
-    Tests for the :func:`append_row` function.
+    Tests for the :func:`dunshire.matrices.append_row` function.
     """
 
     def test_new_dimensions(self):
@@ -58,27 +58,33 @@ class AppendRowTest(TestCase):
 
 class EigenvaluesTest(TestCase):
     """
-    Tests for the :func:`eigenvalues` function.
+    Tests for the :func:`dunshire.matrices.eigenvalues` function.
     """
 
-    def test_eigenvalues_input_untouched(self):
+    def test_eigenvalues_input_not_clobbered(self):
         """
         The eigenvalue functions provided by CVXOPT/LAPACK like to
         overwrite the matrices that you pass into them as
         arguments. This test makes sure that our :func:`eigenvalues`
         function does not do the same.
+
+        We use a ``deepcopy`` here in case the ``copy`` used in the
+        :func:`eigenvalues` function is insufficient. If ``copy`` didn't
+        work and this test used it too, then this test would pass when
+        it shouldn't.
         """
         mat = random_matrix(random_natural())
         symmat = mat + mat.trans()
-        symmat_copy = copy(symmat)
+        symmat_copy = deepcopy(symmat)
         dummy = eigenvalues(symmat)
         self.assertTrue(norm(symmat - symmat_copy) < ABS_TOL)
 
     def test_eigenvalues_of_symmat_are_real(self):
         """
         A real symmetric matrix has real eigenvalues, so if we start
-        with a symmetric matrix, then the two functions :func:`eigenvalues`
-        and :func:`eigenvalues_re` should agree on it.
+        with a symmetric matrix, then the two functions
+        :func:`dunshire.matrices.eigenvalues` and
+        :func:`dunshire.matrices.eigenvalues_re` should agree on it.
         """
         mat = random_matrix(random_natural())
         symmat = mat + mat.trans()
@@ -98,18 +104,24 @@ class EigenvaluesTest(TestCase):
 
 class EigenvaluesRealPartTest(TestCase):
     """
-    Tests for the :func:`eigenvalues_re` function.
+    Tests for the :func:`dunshire.matrices.eigenvalues_re` function.
     """
 
     def test_eigenvalues_re_input_not_clobbered(self):
         """
-        The eigenvalue functions provided by CVXOPT/LAPACK like to
-        overwrite the matrices that you pass into them as
-        arguments. This test makes sure that our :func:`eigenvalues_re`
-        function does not do the same.
+        The eigenvalue functions provided by CVXOPT/LAPACK like
+        to overwrite the matrices that you pass into them as
+        arguments. This test makes sure that our
+        :func:`dunshire.matrices.eigenvalues_re` function does not do
+        the same.
+
+        We use a ``deepcopy`` here in case the ``copy`` used in the
+        :func:`dunshire.matrices.eigenvalues_re` function is
+        insufficient. If ``copy`` didn't work and this test used it too,
+        then this test would pass when it shouldn't.
         """
         mat = random_matrix(random_natural())
-        mat_copy = copy(mat)
+        mat_copy = deepcopy(mat)
         dummy = eigenvalues_re(mat)
         self.assertTrue(norm(mat - mat_copy) < ABS_TOL)
 
@@ -124,14 +136,15 @@ class EigenvaluesRealPartTest(TestCase):
 
 class InnerProductTest(TestCase):
     """
-    Tests for the :func:`inner_product` function.
+    Tests for the :func:`dunshire.matrices.inner_product` function.
     """
 
     def test_inner_product_with_self_is_norm_squared(self):
         """
-        Ensure that the func:`inner_product` and :func:`norm` functions
-        are compatible by checking that the square of the norm of a
-        vector is its inner product with itself.
+        Ensure that the func:`dunshire.matrices.inner_product` and
+        :func:`dunshire.matrices.norm` functions are compatible by
+        checking that the square of the norm of a vector is its inner
+        product with itself.
         """
         vec = random_matrix(random_natural(), 1)
         actual = inner_product(vec, vec)
@@ -141,7 +154,7 @@ class InnerProductTest(TestCase):
 
 class NormTest(TestCase):
     """
-    Tests for the :func:`norm` function.
+    Tests for the :func:`dunshire.matrices.norm` function.
     """
 
     def test_norm_is_nonnegative(self):
@@ -154,7 +167,7 @@ class NormTest(TestCase):
 
 class ConditionNumberTest(TestCase):
     """
-    Tests for the :func:`condition_number` function.
+    Tests for the :func:`dunshire.matrices.condition_number` function.
     """
 
     def test_condition_number_ge_one(self):