Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Testing Research Software
Search
Nikoleta
March 14, 2017
Programming
0
280
Testing Research Software
Slides for the talk Writing tests for research software for PyCon Namibia 2017
Nikoleta
March 14, 2017
Tweet
Share
More Decks by Nikoleta
See All by Nikoleta
A trip to earth science with python as a companion
nikoletav3
0
42
Arcas: Using Python to access open research literature
nikoletav3
1
170
Optimisation of short memory strategies in the Iterated Prisoners Dilemma
nikoletav3
0
51
Arcas
nikoletav3
0
380
SSI Selection Day
nikoletav3
0
370
SWORDS-03-10-2016
nikoletav3
0
44
PyCon UK 2016
nikoletav3
0
150
Other Decks in Programming
See All in Programming
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
1
110
Quine, Polyglot, 良いコード
qnighy
4
640
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
RubyLSPのマルチバイト文字対応
notfounds
0
120
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Facilitating Awesome Meetings
lara
50
6.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Producing Creativity
orderedlist
PRO
341
39k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Transcript
Writing tests for research software @NikoletaGlyn
None
TESTING
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
...
F0 = 0 F1 = 1 Fn = Fn−1 +
Fn−2
main.py def fib(n): if n == 0: return 0 if
n == 1: return 1 return 2 * fib(n - 1)
n 2 3 4 . . . 16 17 18
Fn 1 2 3 . . . 987 1597 2584 Fn−1 1 1 2 . . . 610 987 1597 Fn Fn−1 1.000 2.000 1.500 . . . 1.618 1.618 1.618
n 2 3 4 . . . 16 17 18
Fn 1 2 3 . . . 987 1597 2584 Fn−1 1 1 2 . . . 610 987 1597 Fn Fn−1 1.000 2.000 1.500 . . . 1.618 1.618 1.618 φ 1.61803...
. |-- main.py |-- golden.py
golden.py import main for n in range(10, 100000): golden_ratio =
fib(n) / fib(n - 1) print(golden_ratio)
golden.py import main for n in range(10, 100000): golden_ratio =
fib(n) / fib(n - 1) print(golden_ratio) 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 ...
golden.py import main for n in range(10, 100000): golden_ratio =
fib(n) / fib(n - 1) print(golden_ratio) 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 ... Glynatsi 2017, “SOLVES THE FIBONACCI MYSTERY”
WRITE REVIEW PUBLISH
20% OF GENETIC RESEARCH IS WRONG Gene name errors are
widespread in the scientific literature by Mark Ziemann, Yotam Eren and Assam El-Osta
INDUSTRY
INDUSTRY AMAZON
. |-- main.py |-- golden.py |-- test_main.py
test main.py import unittest import main class TestExample(unittest.TestCase): def test_initial(self):
self.assertEqual(fib(0), 0) self.assertEqual(fib(1), 1) def test_fib(self): self.assertEqual(fib(2), 1) self.assertEqual(fib(3), 2)
test main.py import unittest import main class TestExample(unittest.TestCase): def test_initial(self):
self.assertEqual(fib(0), 0) self.assertEqual(fib(1), 1) def test_fib(self): self.assertEqual(fib(2), 1) self.assertEqual(fib(3), 2) python -m unittest test_main.py
test main.py import unittest import main class TestExample(unittest.TestCase): def test_initial(self):
self.assertEqual(fib(0), 0) self.assertEqual(fib(1), 1) def test_fib(self): self.assertEqual(fib(2), 1) self.assertEqual(fib(3), 2) python -m unittest test_main.py self.assertEqual(fib(2), 1) AssertionError: 2 != 1 ----------------------------- Ran 2 tests in 0.000s FAILED (failures=1)
main.py def fib(n): if n == 0: return 0 if
n == 1: return 1 return 2 * fib(n - 1)
main.py def fib(n): if n == 0: return 0 if
n == 1: return 1 return fib(n - 1) + fib(n - 2)
main.py def fib(n): if n == 0: return 0 if
n == 1: return 1 return fib(n - 1) + fib(n - 2) python -m unittest test_main.py ------------------------------- Ran 2 tests in 0.000s OK
main.py def fib(n): if n == 0: return 0 if
n == 1: return 1 return fib(n - 1) + fib(n - 2) python -m unittest test_main.py ------------------------------- Ran 2 tests in 0.000s OK Glynatsi 2017, “TRYING TO RECLAIM REPUTATION”
Doc Testing
main.py import unittest def fib(n): """Returns the n th fibonacci
number. For example: >>> fib(5) 5 >>> fib(6) 8 >>> fib(5) + fib(6) 13 >>> fib(7) 10 """ if n == 0: return 0 elif n == 1: return 1 else: return fib(n - 1) + fib(n - 2)
python -m doctest main.py Failed example: fib(7) Expected: 10 Got:
13 **************************** 1 items had failures: 1 of 4 in main.fib ***Test Failed*** 1 failures.
main.py import unittest def fib(n): """Returns the n th fibonacci
number. For example: >>> fib(5) 5 >>> fib(6) 8 >>> fib(5) + fib(6) 13 >>> fib(7) 13 """ if n == 0: return 0 elif n == 1: return 1 else: return fib(n - 1) + fib(n - 2)
Property Based Testing
from hypothesis import given from hypothesis.strategies import integers class TestFib(unittest.TestCase):
@given(k=integers(min_value=2)) def test_fib(self, k): self.assertTrue(fib(k), fib(k - 1) + fib(k - 2)) https://github.com/HypothesisWorks @DRMacIver
It’s impossible to conduct research without software, say 7 out
of 10 UK researchers Simon Hettrick uk/blog/2016-09-12-its-impossible-conduct-research-without-out-10-uk- researchers
USE 92%
IMPOSSIBLE 69%
DEVELOP 56%
TRAINING 79%
USE 92% IMPOSSIBLE 69% DEVELOP 56% TRAINING 79%
Axelrod : https://github.com/Axelrod-Python/Axelrod Arcas: https://github.com/Nikoleta-v3/Arcas Ciw: https://github.com/CiwPython/Ciw Pandas: https://github.com/pandas-dev/pandas Skleanr:
http://scikit-learn.org/stable/ Numpy: https://github.com/numpy/numpy cryptography: https://github.com/pyca/cryptography fastnumbers: https://github.com/SethMMorton/fastnumbers yacluster: https://github.com/KrzysiekJ/yacluster binaryornot: https://github.com/audreyr/binaryornot . . .
None
@NikoletaGlyn https://github.com/Nikoleta-v3 @SoftwateSaved @PhoenixCUni