def test_init(self): GL = qm.GaussLegendre(ndom=10, deg=6, lower=1.0, upper=12.0) attributes = ['points', 'weights', 'f', 'alpha', 'singularity', 'initial_weights', 'description'] for att in attributes: self.assertTrue(hasattr(GL, att), msg=str('Missing {} attribute'.format(att)))
def test_base_gauss_weights(self): GQ = qm.GaussLegendre(ndom=10, deg=4, lower=1.0, upper=12.0) gwts = GQ._base_gauss_weights(deg=4, h=0.1) mlgwts = np.array([0.017392742256873, 0.032607257743127, 0.032607257743127, 0.017392742256873]).T self.assertEqual(gwts.size, 4, msg='Expect 4 elements') self.assertEqual(gwts.shape, (4,), msg='Expect shape = (4,)') self.assertTrue(np.allclose(gwts, mlgwts), msg=str('Expect arrays to match: {} neq {}'.format( gwts, mlgwts)))
def test_base_gauss_points(self): GQ = qm.GaussLegendre(ndom=10, deg=4, lower=1.0, upper=12.0) gpts = GQ._base_gauss_points(deg=4) mlgpts = np.array([0.069431844202974, 0.330009478207572, 0.669990521792428, 0.930568155797026]) self.assertEqual(gpts.size, 4, msg='Expect 4 elements') self.assertEqual(gpts.shape, (4,), msg='Expect shape = (4,)') self.assertTrue(np.allclose(gpts, mlgpts), msg=str('Expect arrays to match: {} neq {}'.format( gpts, mlgpts)))
def test_gauss_weights(self): GQ = qm.GaussLegendre(ndom=10, lower=1.0, upper=12.0) gweights = GQ._gauss_weights(ndom=4, deg=4, h=0.1) self.assertEqual(gweights.shape, (4*4,), msg='Expect shape = (16,)')
def test_interval_gauss_points(self): GQ = qm.GaussLegendre(ndom=10, deg=4, lower=1.0, upper=12.0) igp = GQ._interval_gauss_points( base_gpts=GQ._base_gauss_points(deg=4), ndom=4, deg=4, h=0.1, lower=0.) self.assertEqual(igp.shape, (4*4,), msg='Expect shape = (16,)')
def test_integrate(self): GLeg = qm.GaussLegendre(ndom=10, deg=3, lower=0.0, upper=1.0) a = GLeg.integrate(f=self.f) self.assertTrue(isinstance(a, float), msg='Expect float')
def test_update_weights(self): GLeg = qm.GaussLegendre(ndom=10, deg=3, lower=1.0, upper=12.0) GLeg.weights = [] GLeg.update_weights(alpha=0.0) self.assertTrue(isinstance(GLeg.weights, np.ndarray), msg='Weights should be updated.')