Petar Marić avatar Petar Marić committed db824fe

Sped up tests in `tests.integrals.test_integration` by iterating over 3 smaller (yet representative) mode ranges

Comments (0)

Files changed (1)

tests/integrals/test_integration.py

+from itertools import chain
+from math import ceil, floor
 from nose.plugins.skip import SkipTest
 import shutil
 from sympy import Abs
 from tests.tools import assert_almost_equal, assert_equal, assert_less_equal, assert_is #@UnresolvedImport
 
 
-START_MODE = tests.MAX_MODE - 1 # Higher than defaults to speed up tests
-
 INTEGRAL_CLOSED_FORMS_FOR_SIMPLY_SUPPORTED_BEAM = {
     1:   a/2.,
     2:  (a/2.) * (mu_m/a)**2,
     ces.best_roots_cache = _old_best_roots_cache
     shutil.rmtree(disk_cache_dir)
 
+def iterate_over_used_variables(integral, spread=1):
+    """
+    Iterate over 3 smaller (yet representative) mode ranges to speed up tests
+    """
+    mid = tests.MAX_MODE/2
+    mode_ranges = ( 
+        (1, 1 + spread),
+        (mid - int(floor(spread/2.)), mid + int(ceil(spread/2.))),
+        (tests.MAX_MODE - spread, tests.MAX_MODE)
+    )
+    return chain.from_iterable(
+        integral.iterate_over_used_variables(start_mode=start, max_mode=stop)
+        for start, stop in mode_ranges
+    )
+
 def test_integrate():
     for integral_id in BaseIntegral.plugins.valid_ids: #@UndefinedVariable
         integral = BaseIntegral.coerce(integral_id) #@UndefinedVariable
             # beam_type/integral combination
             cache_keys_seen.clear()
             
-            for m, t, v, n in integral.iterate_over_used_variables(start_mode=START_MODE, max_mode=tests.MAX_MODE):
+            for m, t, v, n in iterate_over_used_variables(integral):
                 yield check_integrate, integral_id, beam_type_id, m, t, v, n
 
 def check_integrate(integral_id, beam_type_id, m, t, v, n):
         # Clear out `cache_keys_seen` before testing a new integral
         cache_keys_seen.clear()
         
-        for m, t, v, n in integral.iterate_over_used_variables(start_mode=START_MODE, max_mode=tests.MAX_MODE):
+        for m, t, v, n in iterate_over_used_variables(integral):
             yield check_simply_supported_beam_closed_form, integral_id, m, t, v, n
 
 def check_simply_supported_beam_closed_form(integral_id, m, t, v, n):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.