Ejemplo n.º 1
0
 def test_init(self):
     RS = qm.RiemannSum(n=10, lower=1.0, upper=12.0)
     attributes = ['points', 'weights', 'f', 'alpha', 'grid', 'description',
                   'singularity']
     for att in attributes:
         self.assertTrue(hasattr(RS, att),
                         msg=str('Missing {} attribute'.format(att)))
Ejemplo n.º 2
0
 def test_grid(self):
     RS = qm.RiemannSum()
     grid = RS._rs_grid(lower=1.0, upper=12.0, n=50)
     self.assertTrue(np.allclose(grid, np.linspace(1.0, 12.0, num=50)),
                     msg=str('Expect arrays equal: {} neq {}'.format(
                             grid, np.linspace(1.0, 12.0, num=50))))
     self.assertFalse(np.allclose(grid, np.linspace(2.0, 12.0, num=50)),
                      msg=str('Expect arrays not equal: {} eq {}'.format(
                              grid, np.linspace(2.0, 12.0, num=50))))
Ejemplo n.º 3
0
 def test_rs_points(self):
     RS = qm.RiemannSum(n=10, lower=1.0, upper=12.0)
     self.assertTrue(isinstance(RS.points, np.ndarray),
                     msg='Output numpy array')
     grid = RS._rs_grid(n=10, lower=1.0, upper=12.0)
     jj = grid.size - 1
     values = (grid[1:jj+1] + grid[0:jj])/2
     self.assertTrue(np.allclose(RS.points, values),
                     msg=str('Expect arrays equal: {} neq {}'.format(
                             RS.points, values)))
Ejemplo n.º 4
0
 def different_alphas(self, alpha):
     RS = qm.RiemannSum(alpha=alpha, n=10, lower=1.0, upper=12.0)
     self.assertTrue(isinstance(RS.weights, np.ndarray),
                     msg='Output numpy array')
     grid = RS._rs_grid(n=10, lower=1.0, upper=12.0)
     jj = grid.size - 1
     term1 = (grid[jj] - grid[1:jj+1])**(1-alpha)
     term2 = (grid[jj] - grid[0:jj])**(1-alpha)
     values = -1/(1-alpha)*(term1 - term2)
     self.assertTrue(np.allclose(RS.weights, values),
                     msg=str('Expect arrays equal: {} neq {}'.format(
                             RS.weights, values)))
Ejemplo n.º 5
0
 def test_integrate(self):
     RS = qm.RiemannSum(n=10, lower=0.0, upper=1.0)
     a = RS.integrate(f=self.f)
     self.assertTrue(isinstance(a, float), msg='Expect float')
Ejemplo n.º 6
0
 def test_update_weights(self):
     RS = qm.RiemannSum(n=10, lower=1.0, upper=12.0)
     RS.weights = []
     RS.update_weights(alpha=0.0)
     self.assertTrue(isinstance(RS.weights, np.ndarray),
                     msg='Weights should be updated.')