1 |
jgs |
151 |
# $Id$ |
2 |
|
|
|
3 |
|
|
import os |
4 |
|
|
import sys |
5 |
jgs |
154 |
import unittest |
6 |
jgs |
151 |
|
7 |
|
|
from esys.escript import * |
8 |
|
|
from esys.bruce import * |
9 |
|
|
|
10 |
|
|
""" |
11 |
|
|
|
12 |
|
|
Some simple tests of Bruce. |
13 |
|
|
|
14 |
|
|
""" |
15 |
|
|
|
16 |
jgs |
154 |
class bruceTestCase(unittest.TestCase): |
17 |
jgs |
151 |
|
18 |
jgs |
154 |
def setUp(self): |
19 |
|
|
self.b = Rectangle(11,11,10,10) |
20 |
jgs |
151 |
|
21 |
jgs |
154 |
def tearDown(self): |
22 |
|
|
del self.b |
23 |
jgs |
151 |
|
24 |
jgs |
154 |
def testGetDescription(self): |
25 |
|
|
assert (self.b.getDescription()=="Bruce") |
26 |
jgs |
151 |
|
27 |
jgs |
154 |
def testValidFunctionSpace(self): |
28 |
|
|
assert (self.b.isValidFunctionSpaceType(0)) |
29 |
|
|
assert (self.b.isValidFunctionSpaceType(1)) |
30 |
|
|
assert (not(self.b.isValidFunctionSpaceType(2))) |
31 |
jgs |
151 |
|
32 |
jgs |
154 |
def testFunctionCode(self): |
33 |
|
|
assert (self.b.getContinuousFunctionCode()==0) |
34 |
|
|
assert (self.b.getFunctionCode()==1) |
35 |
jgs |
151 |
|
36 |
jgs |
154 |
def testFunctionSpaceTypeAsString(self): |
37 |
|
|
assert (self.b.functionSpaceTypeAsString(0) == "Bruce_ContinuousFunction") |
38 |
|
|
assert (self.b.functionSpaceTypeAsString(1) == "Bruce_Function") |
39 |
jgs |
151 |
|
40 |
jgs |
154 |
def testGetDim(self): |
41 |
|
|
assert (self.b.getDim()==2) |
42 |
jgs |
151 |
|
43 |
jgs |
154 |
def testGetNumSamples(self): |
44 |
|
|
numSamples = self.b.getNumSamples(0) |
45 |
|
|
assert (numSamples == 121) |
46 |
|
|
numSamples = self.b.getNumSamples(1) |
47 |
|
|
assert (numSamples == 100) |
48 |
jgs |
151 |
|
49 |
jgs |
154 |
def testGetNumDataPointsPerSample(self): |
50 |
|
|
numDataPointsPerSample = self.b.getNumDataPointsPerSample(0) |
51 |
|
|
assert (numDataPointsPerSample == 1) |
52 |
|
|
numDataPointsPerSample = self.b.getNumDataPointsPerSample(1) |
53 |
|
|
assert (numDataPointsPerSample == 1) |
54 |
jgs |
151 |
|
55 |
jgs |
154 |
def testGetReferenceNoFromSampleNo(self): |
56 |
|
|
numSamples = self.b.getNumSamples(0) |
57 |
|
|
for sampleNo in range(numSamples): |
58 |
|
|
assert (sampleNo == self.b.getReferenceNoFromSampleNo(0,sampleNo)) |
59 |
|
|
numSamples = self.b.getNumSamples(1) |
60 |
|
|
for sampleNo in range(numSamples): |
61 |
|
|
assert (sampleNo == self.b.getReferenceNoFromSampleNo(1,sampleNo)) |
62 |
jgs |
151 |
|
63 |
jgs |
154 |
def testTagFromSampleNo(self): |
64 |
|
|
numSamples = self.b.getNumSamples(0) |
65 |
|
|
for sampleNo in range(numSamples): |
66 |
|
|
assert (0 == self.b.getTagFromSampleNo(0,sampleNo)) |
67 |
|
|
numSamples = self.b.getNumSamples(1) |
68 |
|
|
for sampleNo in range(numSamples): |
69 |
|
|
assert (0 == self.b.getTagFromSampleNo(1,sampleNo)) |
70 |
|
|
|
71 |
|
|
def testBrick(self): |
72 |
|
|
brick = Brick(11,11,11,10,10,10) |
73 |
|
|
assert (brick.getDim()==3) |
74 |
|
|
|
75 |
|
|
def testRectangle(self): |
76 |
|
|
rectangle = Rectangle(11,11,10,10) |
77 |
|
|
assert (rectangle.getDim()==2) |
78 |
|
|
|
79 |
|
|
def testSaveVTK(self): |
80 |
|
|
filename = "testVTK.vts" |
81 |
|
|
fs1 = ContinuousFunction(self.b) |
82 |
|
|
fs2 = Function(self.b) |
83 |
|
|
testData1 = Scalar(1.0, fs1) |
84 |
|
|
testData2 = Scalar(1.0, fs2) |
85 |
|
|
testData3 = Vector(1.0, fs1) |
86 |
|
|
testData4 = Vector(1.0, fs2) |
87 |
|
|
testData5 = Tensor(1.0, fs1) |
88 |
|
|
testData6 = Tensor(1.0, fs2) |
89 |
|
|
dict = {'testData1':testData1, |
90 |
|
|
'testData2':testData2, |
91 |
|
|
# 'testData3':testData3, |
92 |
|
|
'testData4':testData4, |
93 |
|
|
'testData5':testData5, |
94 |
|
|
'testData6':testData6} |
95 |
|
|
self.b.saveVTK(filename, dict) |
96 |
|
|
|
97 |
|
|
if __name__ == '__main__': |
98 |
|
|
suite=unittest.TestSuite() |
99 |
|
|
suite.addTest(unittest.makeSuite(bruceTestCase)) |
100 |
|
|
unittest.TextTestRunner(verbosity=2).run(suite) |
101 |
|
|
|
102 |
jgs |
151 |
sys.exit(0) |