From d988995ea403db9d6f63a7101d31b8d624fc379e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 1 Nov 2016 18:01:51 -0400 Subject: [PATCH] Improve the two no-clobber tests with deepcopy(). --- test/matrices_test.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/matrices_test.py b/test/matrices_test.py index ce57c7d..49d8be9 100644 --- a/test/matrices_test.py +++ b/test/matrices_test.py @@ -2,7 +2,7 @@ Unit tests for the functions in the ``matrices`` module. """ -from copy import copy +from copy import deepcopy from unittest import TestCase from dunshire.matrices import (append_col, append_row, condition_number, @@ -67,10 +67,15 @@ class EigenvaluesTest(TestCase): 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) @@ -107,9 +112,14 @@ class EigenvaluesRealPartTest(TestCase): 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. + + We use a ``deepcopy`` here in case the ``copy`` used in the + :func:`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) -- 2.44.2