← Back to team overview

dolfin team mailing list archive

Fwd: [Branch ~dolfin-core/dolfin/trunk] Rev 7064: Add unit test for float(Function(R)).

 

I has to comment this test out because it breaks the buildbot in parallel.

Garth


---------- Forwarded message ----------
From:  <noreply@xxxxxxxxxxxxx>
Date: Thu, Nov 1, 2012 at 9:33 AM
Subject: [Branch ~dolfin-core/dolfin/trunk] Rev 7064: Add unit test
for float(Function(R)).
To: Garth Wells <gnw20@xxxxxxxxx>


------------------------------------------------------------
revno: 7064
committer: Martin Sandve Alnæs <martinal@xxxxxxxxx>
branch nick: work
timestamp: Thu 2012-11-01 10:32:53 +0100
message:
  Add unit test for float(Function(R)).
modified:
  test/unit/function/python/Function.py


--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/trunk

Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
To unsubscribe from this branch go to
https://code.launchpad.net/~dolfin-core/dolfin/trunk/+edit-subscription

=== modified file 'test/unit/function/python/Function.py'
--- test/unit/function/python/Function.py       2012-08-24 11:33:59 +0000
+++ test/unit/function/python/Function.py       2012-11-01 09:32:53 +0000
@@ -24,6 +24,7 @@
 from dolfin import *

 mesh = UnitCube(8, 8, 8)
+R = FunctionSpace(mesh, 'R', 0)
 V = FunctionSpace(mesh, 'CG', 1)
 W = VectorFunctionSpace(mesh, 'CG', 1)

@@ -50,6 +51,16 @@

         self.assertTrue(all(u_values==1))

+    def test_float_conversion(self):
+        c = Function(R)
+        self.assertTrue(float(c) == 0.0)
+        c.vector()[:] = 1.23
+        self.assertTrue(float(c) == 1.23)
+        c.assign(Constant(2.34))
+        self.assertTrue(float(c) == 2.34)
+        c = Constant(3.45)
+        self.assertTrue(float(c) == 3.45)
+
 class Interpolate(unittest.TestCase):

     def test_interpolation_mismatch_rank0(self):
@@ -74,12 +85,12 @@
         if MPI.num_processes() == 1:
             mesh1 = UnitSquare(3,3)
             V1 = FunctionSpace(mesh1, "CG", 1)
-
+
             parameters["allow_extrapolation"] = True
             f1 = Function(V1)
             f1.vector()[:] = 1.0
             self.assertAlmostEqual(f1(0.,-1), 1.0)
-
+
             mesh2 = UnitTriangle()
             V2 = FunctionSpace(mesh2, "CG", 1)





-- 
Garth N. Wells
Department of Engineering, University of Cambridge
http://www.eng.cam.ac.uk/~gnw20
=== modified file 'test/unit/function/python/Function.py'
--- test/unit/function/python/Function.py	2012-08-24 11:33:59 +0000
+++ test/unit/function/python/Function.py	2012-11-01 09:32:53 +0000
@@ -24,6 +24,7 @@
 from dolfin import *
 
 mesh = UnitCube(8, 8, 8)
+R = FunctionSpace(mesh, 'R', 0)
 V = FunctionSpace(mesh, 'CG', 1)
 W = VectorFunctionSpace(mesh, 'CG', 1)
 
@@ -50,6 +51,16 @@
 
         self.assertTrue(all(u_values==1))
 
+    def test_float_conversion(self):
+        c = Function(R)
+        self.assertTrue(float(c) == 0.0)
+        c.vector()[:] = 1.23
+        self.assertTrue(float(c) == 1.23)
+        c.assign(Constant(2.34))
+        self.assertTrue(float(c) == 2.34)
+        c = Constant(3.45)
+        self.assertTrue(float(c) == 3.45)
+
 class Interpolate(unittest.TestCase):
 
     def test_interpolation_mismatch_rank0(self):
@@ -74,12 +85,12 @@
         if MPI.num_processes() == 1:
             mesh1 = UnitSquare(3,3)
             V1 = FunctionSpace(mesh1, "CG", 1)
-            
+
             parameters["allow_extrapolation"] = True
             f1 = Function(V1)
             f1.vector()[:] = 1.0
             self.assertAlmostEqual(f1(0.,-1), 1.0)
-        
+
             mesh2 = UnitTriangle()
             V2 = FunctionSpace(mesh2, "CG", 1)
 


Follow ups