This commit is contained in:
Stephen Mardson McQuay
2009-12-27 10:48:27 -07:00
commit 961b3b7b26
19 changed files with 560 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/python
import unittest
import baker
import numpy as np
import scipy.spatial
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.l = [[-1, 1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
self.approx_fmt = "%0.6f"
def testGetPhis(self):
X = [0,0]
r = [[-1, -1], [0, 2], [1, -1]]
result = baker.get_phis(X, r)
result = [self.approx_fmt % i for i in result]
right_answer = [self.approx_fmt % i for i in [1/3.0, 1/3.0, 1/3.0]]
for a,b in zip(result, right_answer):
self.assertEqual(a,b)
def testGetPhis2(self):
X = [0.5,0.25]
r = [[0, 0], [1, 0], [1, 1]]
result = baker.get_phis(X, r)
right_answer = [0.5, 0.25, 0.25]
for a,b in zip(result, right_answer):
self.assertEqual(a,b)
def testQlinear(self):
X = [0.5, 0.25]
r = [[0, 0], [1, 0], [1, 1]]
q = [1, 0, 0]
result = baker.qlinear(X, r, q)
right_answer = 0.5
self.assertEqual(result, right_answer)
def testRunBaker(self):
X = [0.5, 0.25]
all_points = [
[ 0, 0], # 0
[ 1, 0], # 1
[ 1, 1], # 2
[ 0, 1], # 3
[ 1,-1], # 4
[ 0,-1], # 5
[-1, 1], # 6
[-1, 0], # 7
[-1,-1], # 8
]
q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
tree = scipy.spatial.KDTree(all_points)
baker.run_baker(X,
result = 3
right_answer = 5
self.assertEqual(result, right_answer)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite)
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/python
import delaunay
import subprocess
QFILE = '/tmp/forQhull.txt'
l = [[-1, 1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
qdelauney_file = open(QFILE, 'w')
qdelauney_file.write("%d\n" % len(l[0]))
qdelauney_file.write("%d\n" % len(l))
for i in l:
qdelauney_file.write("%0.3f %0.3f\n" % (i[0], i[1]))
dt = delaunay.Triangulation(l)
print dt.indices
answer = [
[4,1,3],
[1,5,0],
[5,1,4],
[7,3,6],
[7,4,3],
[7,5,4],
[5,7,8],
]
print answer == dt.indices
print dt.indices
print "now run /usr/bin/qdelaunay Qt i < %s" % QFILE
Executable
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/python
import random
import unittest
import delaunay
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.l = [[-1, 1], [-1, 0], [-1, 1], [0, -1], [0, 0], [0, 1], [1, -1], [1, 0], [1, 1]]
def testQhull(self):
dt = delaunay.Triangulation(self.l)
answer = [
[4,1,3],
[1,5,0],
[5,1,4],
[7,3,6],
[7,4,3],
[7,5,4],
[5,7,8],
]
self.assertEqual(dt.indices, answer)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=5).run(suite)