# -*- coding: utf-8 -*-
#
import unittest

import numpy
import voropy

from helpers import download_mesh


class CurlTest(unittest.TestCase):

    def setUp(self):
        return

    def _run_test(self, mesh):
        # Create circular vector field 0.5 * (y, -x, 0)
        # which has curl (0, 0, 1).
        A = numpy.array([
            [-0.5 * coord[1], 0.5 * coord[0], 0.0]
            for coord in mesh.node_coords
            ])
        # Compute the curl numerically.
        B = mesh.compute_curl(A)

        # mesh.write(
        #     'curl.vtu',
        #     point_data={'A': A},
        #     cell_data={'B': B}
        #     )

        tol = 1.0e-14
        for b in B:
            self.assertAlmostEqual(b[0], 0.0, delta=tol)
            self.assertAlmostEqual(b[1], 0.0, delta=tol)
            self.assertAlmostEqual(b[2], 1.0, delta=tol)
        return

    def test_pacman(self):
        filename = download_mesh(
                'pacman.msh',
                '2da8ff96537f844a95a83abb48471b6a'
                )
        mesh, _, _, _ = voropy.read(filename)
        self._run_test(mesh)
        return


if __name__ == '__main__':
    unittest.main()

@@ -23,25 +23,8 @@
 -%0A#%0A
-import unittest%0A%0A
 impo
@@ -87,116 +87,24 @@
 h%0A%0A%0A
-class CurlTest(unittest.TestCase):%0A%0A    def setUp(self):%0A        return%0A%0A    def _run_test(self, 
+def _run(
 mesh):%0A
-    
     
@@ -151,20 +151,16 @@
  -x, 0)%0A
-    
     # wh
@@ -187,20 +187,16 @@
 1).%0A    
- 
-   
 A = nump
@@ -205,20 +205,16 @@
 array(%5B%0A
-    
         
@@ -256,28 +256,24 @@
 .0%5D%0A        
-   
- 
 for coord in
@@ -302,19 +302,11 @@
     
-    %5D)%0A    
+%5D)%0A
     
@@ -337,20 +337,16 @@
 ically.%0A
-    
     B = 
@@ -367,20 +367,16 @@
 url(A)%0A%0A
-    
     # me
@@ -385,28 +385,24 @@
 .write(%0A    
-  
-  
 #     'curl.
@@ -407,20 +407,16 @@
 l.vtu',%0A
-    
     #   
@@ -438,28 +438,24 @@
 A': A%7D,%0A    
-   
- 
 #     cell_d
@@ -467,20 +467,16 @@
 'B': B%7D%0A
-    
     #   
@@ -480,20 +480,16 @@
      )%0A%0A
-    
     tol 
@@ -498,28 +498,24 @@
 1.0e-14%0A    
- 
-   
 for b in B:%0A
@@ -526,56 +526,36 @@
     
-    self.assertAlmostEqual
+assert abs
 (b%5B0%5D
-,
+ -
  0.0
-, delta=
+) %3C 
 tol
-)
 %0A   
@@ -563,118 +563,74 @@
     
-    self.assertAlmostEqual
+assert abs
 (b%5B1%5D
-,
+ -
  0.0
-, delta=tol)%0A            self.assertAlmostEqual
+) %3C tol%0A        assert abs
 (b%5B2%5D
-,
+ -
  1.0
-, delta=tol)%0A    
+) %3C tol%0A
     
@@ -637,20 +637,17 @@
 return%0A%0A
-    
+%0A
 def test
@@ -658,19 +658,11 @@
 man(
-self
 ):%0A
-    
     
@@ -699,20 +699,16 @@
         
-    
 'pacman.
@@ -725,20 +725,16 @@
         
-  
-  
 '2da8ff9
@@ -776,22 +776,14 @@
     
-    )%0A   
+)%0A
     
- 
 mesh
@@ -824,37 +824,19 @@
     
-    self._run_test
+_run
 (mesh)%0A
-    
     
@@ -879,20 +879,18 @@
     
-unittest.
+test_pac
 ma
-i
 n()%0A

update curl test