def setUp(self): """Sets up all variables needed for DavidsonOptions class.""" self.max_subspace = 10 self.max_iterations = 100 self.eps = 1e-7 self.davidson_options = DavidsonOptions(self.max_subspace, self.max_iterations, self.eps)
def setUp(self): """Sets up all variables needed for SparseDavidson class.""" logging.basicConfig(level=logging.INFO) self.dimension = 1000 self.sparse_matrix = generate_sparse_matrix(self.dimension) self.davidson_options = DavidsonOptions(max_subspace=100, max_iterations=50, real_only=True) # Checks for built-in eigh() function. self.eigen_values, self.eigen_vectors = numpy.linalg.eigh( self.sparse_matrix) self.assertAlmostEqual( get_difference(self.sparse_matrix, self.eigen_values, self.eigen_vectors), 0) # Makes sure eigenvalues are sorted. self.eigen_values = sorted(self.eigen_values)
class DavidsonOptionsTest(unittest.TestCase): """"Tests for DavidsonOptions class.""" def setUp(self): """Sets up all variables needed for DavidsonOptions class.""" self.max_subspace = 10 self.max_iterations = 100 self.eps = 1e-7 self.davidson_options = DavidsonOptions(self.max_subspace, self.max_iterations, self.eps) def test_init(self): """Tests vars in __init__().""" self.assertEqual(self.davidson_options.max_subspace, self.max_subspace) self.assertEqual(self.davidson_options.max_iterations, self.max_iterations) self.assertAlmostEqual(self.davidson_options.eps, self.eps, places=8) self.assertFalse(self.davidson_options.real_only) def test_set_dimension_small(self): """Tests set_dimension() with a small dimension.""" dimension = 6 self.davidson_options.set_dimension(dimension) self.assertEqual(self.davidson_options.max_subspace, dimension + 1) def test_set_dimension_large(self): """Tests set_dimension() with a large dimension not affecting max_subspace.""" self.davidson_options.set_dimension(60) self.assertEqual(self.davidson_options.max_subspace, self.max_subspace) def test_invalid_max_subspace(self): """Test for invalid max_subspace.""" with self.assertRaises(ValueError): DavidsonOptions(max_subspace=1) def test_invalid_max_iterations(self): """Test for invalid max_iterations.""" with self.assertRaises(ValueError): DavidsonOptions(max_iterations=0) def test_invalid_eps(self): """Test for invalid eps.""" with self.assertRaises(ValueError): DavidsonOptions(eps=-1e-6) def test_invalid_dimension(self): """Test for invalid dimension.""" with self.assertRaises(ValueError): self.davidson_options.set_dimension(0)
def test_invalid_eps(self): """Test for invalid eps.""" with self.assertRaises(ValueError): DavidsonOptions(eps=-1e-6)
def test_invalid_max_iterations(self): """Test for invalid max_iterations.""" with self.assertRaises(ValueError): DavidsonOptions(max_iterations=0)
def test_invalid_max_subspace(self): """Test for invalid max_subspace.""" with self.assertRaises(ValueError): DavidsonOptions(max_subspace=1)