Page - 75 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 75 -
Text of the Page - 75 -
3.4 Testing 75
Makinga test function is amatter of choosingf,F,a, andb, and thenchecking
thevalueofri for the largest i:
def test_trapezoidal_conv_rate():
"""Check empirical convergence rates against the expected -2."""
from math import exp
v = lambda t: 3*(t**2)*exp(t**3)
V = lambda t: exp(t**3)
a = 1.1; b = 1.9
r = convergence_rates(v, V, a, b, 14)
print r
tol = 0.01
msg = str(r[-4:]) # show last 4 estimated rates
assert (abs(r[-1]) - 2) < tol, msg
Running the test shows that all ri, except the first one, equal the target limit 2
within twodecimals. Thisobservationsuggest a toleranceof10 2.
Remarkaboutversioncontroloffiles
Having a suite of test functions for automatically checking that your soft-
wareworks is considered as a fundamental requirement for reliable computing.
Equally important isasystemthatcankeeptrackofdifferentversionsof thefiles
and the tests, knownas a version control system. Todayβsmost popular version
control system isGit4,which the authors strongly recommend the reader to use
forprogrammingandwriting reports. ThecombinationofGit andcloudstorage
such asGitHub is a very commonway of organizing scientific or engineering
work. Wehave a quick intro5 toGit andGitHub that gets you up and running
withinminutes.
The typicalworkflowwithGitgoesas follows.
1. Beforeyoustartworkingwithfiles,makesureyouhave the latest versionof
thembyrunninggit pull.
2. Editfiles, removeorcreatefiles (newfilesmustbe registeredbygit add).
3. When a natural piece of work is done, commit your changes by the git
commitcommand.
4. Implementyourchangesalso in thecloudbydoinggit push.
A nice feature ofGit is that people can edit the samefile at the same time and
very oftenGit will be able to automaticallymerge the changes (!). Therefore,
versioncontrol is crucialwhenyouworkwithothersorwhenyoudoyourwork
on different types of computers. Another key feature is that anyone can at any
timeview thehistory of afile, seewhodidwhatwhen, and roll back the entire
file collection to a previouscommit. This feature is, of course, fundamental for
reliablework.
4https://en.wikipedia.org/wiki/Git_(software)
5http://hplgit.github.io/teamods/bitgit/Langtangen_bitgit-bootstrap.html
back to the
book Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations β Python
A Gentle Introduction to Numerical Simulations with Python
- Title
- Programming for Computations β Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2016
- Language
- English
- License
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 248
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik