--- Begin Message ---
------------------------------------------------------------
revno: 5704
committer: Garth N. Wells <gnw20@xxxxxxxxx>
branch nick: dolfin-all
timestamp: Sat 2011-02-26 09:41:43 +0000
message:
Add Face.py unit test.
Some of the unit test files are getting too long and confusing. I suggest that we add a test.oy file for each class - it will be a lot of files, but it makes it easy to handle the tests class-by-class.
added:
test/unit/mesh/python/Face.py
modified:
dolfin/mesh/Point.h
--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/main
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/main/+edit-subscription
=== modified file 'dolfin/mesh/Point.h'
--- dolfin/mesh/Point.h 2010-03-07 12:32:45 +0000
+++ dolfin/mesh/Point.h 2011-02-26 09:41:43 +0000
@@ -45,69 +45,69 @@
~Point() {};
/// Return address of coordinate in direction i
- double& operator[] (uint i)
+ double& operator[] (uint i)
{ assert(i < 3); return _x[i]; }
/// Return coordinate in direction i
- double operator[] (uint i) const
+ double operator[] (uint i) const
{ assert(i < 3); return _x[i]; }
/// Return x-coordinate
- double x() const
+ double x() const
{ return _x[0]; }
/// Return y-coordinate
- double y() const
+ double y() const
{ return _x[1]; }
/// Return z-coordinate
- double z() const
+ double z() const
{ return _x[2]; }
/// Return coordinate array
- const double* coordinates() const
+ const double* coordinates() const
{ return _x; }
/// Compute sum of two points
- Point operator+ (const Point& p) const
+ Point operator+ (const Point& p) const
{ Point q(_x[0] + p._x[0], _x[1] + p._x[1], _x[2] + p._x[2]); return q; }
/// Compute difference of two points
- Point operator- (const Point& p) const
+ Point operator- (const Point& p) const
{ Point q(_x[0] - p._x[0], _x[1] - p._x[1], _x[2] - p._x[2]); return q; }
/// Add given point
- const Point& operator+= (const Point& p)
+ const Point& operator+= (const Point& p)
{ _x[0] += p._x[0]; _x[1] += p._x[1]; _x[2] += p._x[2]; return *this; }
/// Subtract given point
- const Point& operator-= (const Point& p)
+ const Point& operator-= (const Point& p)
{ _x[0] -= p._x[0]; _x[1] -= p._x[1]; _x[2] -= p._x[2]; return *this; }
/// Multiplication with scalar
- Point operator* (double a) const
+ Point operator* (double a) const
{ Point p(a*_x[0], a*_x[1], a*_x[2]); return p; }
/// Incremental multiplication with scalar
- const Point& operator*= (double a)
+ const Point& operator*= (double a)
{ _x[0] *= a; _x[1] *= a; _x[2] *= a; return *this; }
/// Division by scalar
- Point operator/ (double a) const
+ Point operator/ (double a) const
{ Point p(_x[0]/a, _x[1]/a, _x[2]/a); return p; }
/// Incremental division by scalar
- const Point& operator/= (double a)
+ const Point& operator/= (double a)
{ _x[0] /= a; _x[1] /= a; _x[2] /= a; return *this; }
/// Assignment operator
- const Point& operator= (const Point& p)
+ const Point& operator= (const Point& p)
{ _x[0] = p._x[0]; _x[1] = p._x[1]; _x[2] = p._x[2]; return *this; }
-
-#ifdef HAS_CGAL
+
+ #ifdef HAS_CGAL
///Conversion operator to appropriate CGAL Point_3 class.
template <typename Kernel>
- operator CGAL::Point_3<Kernel>() const
+ operator CGAL::Point_3<Kernel>() const
{ return CGAL::Point_3<Kernel>(_x[0],_x[1],_x[2]); }
///Constructor taking a CGAL::Point_3. Allows conversion from CGAL Point_3 class to Point class.
@@ -117,9 +117,9 @@
///Provides a CGAL bounding box, using conversion operator.
template <typename Kernel>
- CGAL::Bbox_3 bbox()
+ CGAL::Bbox_3 bbox()
{ return CGAL::Point_3<Kernel>(*this).bbox(); }
-#endif
+ #endif
/// Compute distance to given point
double distance(const Point& p) const;
=== added file 'test/unit/mesh/python/Face.py'
--- test/unit/mesh/python/Face.py 1970-01-01 00:00:00 +0000
+++ test/unit/mesh/python/Face.py 2011-02-26 09:41:43 +0000
@@ -0,0 +1,39 @@
+"""Unit tests for the Facet class"""
+
+__author__ = "Garth N. Wells (gnw20@xxxxxxxxx)"
+__date__ = "2011-02-26"
+__copyright__ = "Copyright (C) 2011 Garth N. Wells"
+__license__ = "GNU LGPL Version 2.1"
+
+import unittest
+from dolfin import *
+
+cube = UnitCube(5, 5, 5)
+
+class Area(unittest.TestCase):
+
+ def testArea(self):
+ """Iterate over faces and sum area."""
+ area = 0.0
+ for f in faces(cube):
+ area += f.area()
+ self.assertAlmostEqual(area, 39.21320343559672494393)
+
+class Normal(unittest.TestCase):
+
+ def testNormalPoint(self):
+ """Compute normal vector to each face."""
+ for f in faces(cube):
+ n = f.normal()
+ self.assertAlmostEqual(n.norm(), 1.0)
+
+ def testNormalComponent(self):
+ """Compute normal vector components to each face."""
+ D = cube.topology().dim()
+ for f in faces(cube):
+ n = [f.normal(i) for i in range(D)]
+ norm = sum(map(lambda x: x*x, n))
+ self.assertAlmostEqual(norm, 1.0)
+
+if __name__ == "__main__":
+ unittest.main()
--- End Message ---