5
5
@author: prmiles
6
6
"""
7
7
8
+ import sympy as sp
8
9
import numpy as np
9
10
import unittest
10
11
from pyfod .GaussLaguerre import GaussLaguerre
13
14
def f (t ):
14
15
return np .cos (t )
15
16
17
+ def fsp (t ):
18
+ return sp .cos (t )
19
+
16
20
17
21
# --------------------------
18
- class Initialization (unittest .TestCase ):
22
+ class Initialization_non_extended (unittest .TestCase ):
19
23
20
24
def test_init (self ):
21
- GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 )
25
+ GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 , extend_precision = False )
22
26
self .assertTrue (hasattr (GQ , 'f' ), msg = 'Expect attribute f to exist' )
23
27
self .assertEqual (GQ .f , None , msg = 'Expect value of None' )
24
28
self .assertEqual (GQ .points .size , 10 , msg = 'Expect 10 nodes' )
@@ -28,7 +32,7 @@ def test_init(self):
28
32
29
33
def test_init_with_f (self ):
30
34
31
- GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 , alpha = 0.5 , f = f )
35
+ GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 , alpha = 0.5 , f = f , extend_precision = False )
32
36
self .assertTrue (hasattr (GQ , 'f' ), msg = 'Expect attribute f to exist' )
33
37
self .assertEqual (GQ .f , f , msg = 'Expect function f' )
34
38
self .assertEqual (GQ .points .size , 10 , msg = 'Expect 10 nodes' )
@@ -37,19 +41,60 @@ def test_init_with_f(self):
37
41
38
42
39
43
# --------------------------
40
- class Integrate (unittest .TestCase ):
44
+ class Initialization_with_extended (unittest .TestCase ):
45
+
46
+ def test_init (self ):
47
+ GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 )
48
+ self .assertTrue (hasattr (GQ , 'f' ), msg = 'Expect attribute f to exist' )
49
+ self .assertEqual (GQ .f , None , msg = 'Expect value of None' )
50
+ self .assertEqual (len (GQ .points ), 10 , msg = 'Expect 10 nodes' )
51
+ self .assertEqual (len (GQ .weights ), 10 , msg = 'Expect 10 weights' )
52
+ self .assertEqual (GQ .alpha , 0 , msg = 'Expect alpha eq 0' )
53
+
54
+
55
+ def test_init_with_f (self ):
56
+
57
+ GQ = GaussLaguerre (N = 10 , start = 1.0 , finish = 12.0 , alpha = 0.5 , f = fsp )
58
+ self .assertTrue (hasattr (GQ , 'f' ), msg = 'Expect attribute f to exist' )
59
+ self .assertEqual (GQ .f , fsp , msg = 'Expect function fsp' )
60
+ self .assertEqual (len (GQ .points ), 10 , msg = 'Expect 10 nodes' )
61
+ self .assertEqual (len (GQ .weights ), 10 , msg = 'Expect 10 weights' )
62
+ self .assertEqual (GQ .alpha , 0.5 , msg = 'Expect alpha eq 0.5' )
63
+
64
+
65
+ # --------------------------
66
+ class Integrate_non_extended (unittest .TestCase ):
41
67
42
68
def test_no_f (self ):
43
- GQ = GaussLaguerre ()
69
+ GQ = GaussLaguerre (extend_precision = False )
44
70
with self .assertRaises (SystemExit ):
45
71
GQ .integrate ()
46
72
47
73
def test_with_f (self ):
48
- GQ = GaussLaguerre ()
74
+ GQ = GaussLaguerre (extend_precision = False )
49
75
a = GQ .integrate (f = f )
50
76
self .assertEqual (a .size , 1 , msg = 'Expect float return' )
51
77
52
78
def test_with_alpha (self ):
53
- GQ = GaussLaguerre ()
79
+ GQ = GaussLaguerre (extend_precision = False )
54
80
a = GQ .integrate (f = f , alpha = 0.5 )
55
- self .assertEqual (a .size , 1 , msg = 'Expect float return' )
81
+ self .assertEqual (a .size , 1 , msg = 'Expect float return' )
82
+
83
+
84
+ # --------------------------
85
+ class Integrate_with_extended (unittest .TestCase ):
86
+
87
+ def test_no_f (self ):
88
+ GQ = GaussLaguerre ()
89
+ with self .assertRaises (SystemExit ):
90
+ GQ .integrate ()
91
+
92
+ def test_with_f (self ):
93
+ GQ = GaussLaguerre ()
94
+ a = GQ .integrate (f = fsp )
95
+ self .assertTrue (a .is_Float , msg = 'Expect float return' )
96
+
97
+ def test_with_alpha (self ):
98
+ GQ = GaussLaguerre ()
99
+ a = GQ .integrate (f = fsp , alpha = 0.5 )
100
+ self .assertTrue (a .is_Float , msg = 'Expect float return' )
0 commit comments