Changeset 2509 for inundation/utilities/test_numerical_tools.py
- Timestamp:
- Mar 9, 2006, 2:29:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/utilities/test_numerical_tools.py
r1910 r2509 5 5 from Numeric import zeros, array, allclose 6 6 from math import sqrt, pi 7 from pyvolution.config import epsilon 7 8 8 9 from numerical_tools import * … … 66 67 assert B.typecode() == 'd' 67 68 assert A == B 68 assert A is not B #Not the same object 69 assert A is not B #Not the same object 70 71 72 def test_gradient(self): 73 x0 = 0.0; y0 = 0.0; z0 = 0.0 74 x1 = 1.0; y1 = 0.0; z1 = -1.0 75 x2 = 0.0; y2 = 1.0; z2 = 0.0 76 77 zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2) 78 79 assert zx == -1.0 80 assert zy == 0.0 81 82 def test_gradient_more(self): 83 x0 = 2.0/3; y0 = 2.0/3 84 x1= 8.0/3; y1 = 2.0/3 85 x2 = 2.0/3; y2 = 8.0/3 86 87 q0 = 2.0+2.0/3 88 q1 = 8.0+2.0/3 89 q2 = 2.0+8.0/3 90 91 #Gradient of fitted pwl surface 92 a, b = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2) 93 94 assert abs(a - 3.0) < epsilon 95 assert abs(b - 1.0) < epsilon 96 97 98 def test_gradient2(self): 99 """Test two-point gradient 100 """ 101 102 x0 = 5.0; y0 = 5.0; z0 = 10.0 103 x1 = 8.0; y1 = 2.0; z1 = 1.0 104 x2 = 8.0; y2 = 8.0; z2 = 10.0 105 106 #Reference 107 zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2) 108 a, b = gradient2(x0, y0, x1, y1, z0, z1) 109 110 assert zx == a 111 assert zy == b 112 113 z2_computed = z0 + a*(x2-x0) + b*(y2-y0) 114 assert z2_computed == z2 115 116 def test_gradient2_more(self): 117 """Test two-point gradient more 118 """ 119 x0 = 2.0; y0 = 2.0 120 x1 = 8.0; y1 = 3.0 121 x2 = 1.0; y2 = 8.0 122 123 q0 = 2.0 124 q1 = 8.0 125 q2 = q0 126 127 #Gradient of fitted pwl surface 128 a_ref, b_ref = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2) 129 a, b = gradient2(x0, y0, x1, y1, q0, q1) 130 131 assert a == a_ref 132 assert b == b_ref 133 134 135 def test_that_C_extension_compiles(self): 136 FN = 'util_ext.c' 137 try: 138 import util_ext 139 except: 140 from compile import compile 141 142 try: 143 compile(FN) 144 except: 145 raise 'Could not compile %s' %FN 146 else: 147 import util_ext 148 149 150 def test_gradient_C_extension(self): 151 from util_ext import gradient as gradient_c 152 153 x0 = 2.0/3; y0 = 2.0/3 154 x1= 8.0/3; y1 = 2.0/3 155 x2 = 2.0/3; y2 = 8.0/3 156 157 q0 = 2.0+2.0/3 158 q1 = 8.0+2.0/3 159 q2 = 2.0+8.0/3 160 161 #Gradient of fitted pwl surface 162 a, b = gradient_c(x0, y0, x1, y1, x2, y2, q0, q1, q2) 163 164 assert abs(a - 3.0) < epsilon 165 assert abs(b - 1.0) < epsilon 166 167 168 def test_gradient_C_extension3(self): 169 from util_ext import gradient as gradient_c 170 171 from RandomArray import uniform, seed 172 seed(17, 53) 173 174 x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6) 175 176 q0 = uniform(0.0, 10.0, 4) 177 q1 = uniform(1.0, 3.0, 4) 178 q2 = uniform(7.0, 20.0, 4) 179 180 181 for i in range(4): 182 #Gradient of fitted pwl surface 183 from util import gradient_python 184 a_ref, b_ref = gradient(x0, y0, x1, y1, x2, y2, 185 q0[i], q1[i], q2[i]) 186 187 #print a_ref, b_ref 188 a, b = gradient_c(x0, y0, x1, y1, x2, y2, 189 q0[i], q1[i], q2[i]) 190 191 #print a, a_ref, b, b_ref 192 assert abs(a - a_ref) < epsilon 193 assert abs(b - b_ref) < epsilon 194 195 69 196 70 197
Note: See TracChangeset
for help on using the changeset viewer.