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