-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Code Testing | ||
|
||
One of the most important factors for a scientific code is being correct. | ||
We want to be able to check that the code is giving the answer we expect and that any changes to the code are not inadvertantly changing the output. | ||
This is why tests are a part of high quality code. | ||
|
||
# Types of Tests | ||
|
||
Unit tests are small tests that each test a particullar part (or unit) of the code. | ||
Unit tests are used to test each function one at a time, and in some cases might even test just part of a function or class. | ||
|
||
Integration tests check that pieces of code are working together as expected. | ||
This is used for multiple functions at the same time. | ||
|
||
Regression tests look at the final answer for an example input and are used to check that changes to one part of the code are not changing the overall performance. | ||
|
||
# Code Coverage | ||
|
||
Code coverage is a metric related to how much of your code is being tested. | ||
Low code coverage suggests that there are parts of the code that may or may not contain bugs. | ||
In this case, writting more tests is recommended. | ||
|
||
High code coverage is good, but does not guarentee that all bugs have been found. | ||
Some functions might need more than one test to cover all the possible input cases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Pytest | ||
|
||
Pytest is one example of a program used for running tests. | ||
The documentation for pytest can be found [here](https://docs.pytest.org) | ||
|
||
*Activity* Change to the code_testing directory of the software workshop. | ||
Look at the functions.py code and the test_functions.py. | ||
Try running the test. Does it pass? if not why not and can you fix the code so that the test passes? | ||
Does the test cover all the functionality? Try writting more tests. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import numpy as nmp | ||
|
||
def frequency_calculation(lamdas, temp): | ||
def frequency_calculation(lamda): | ||
""" | ||
Calculate the frequency based on the equation | ||
frequency = 1/(2pi) * sqrt(x) | ||
""" | ||
pi = nmp.pi | ||
kt = 4.11e-21 * temp / 298 | ||
frequencies = 1/(2*pi) * nmp.sqrt(lamdas/kt) | ||
|
||
# calculate the frequency | ||
frequency = 1/(pi) * nmp.sqrt(lamda) | ||
|
||
return frequency | ||
|
||
|
||
return frequencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from code_testing import functions as fun | ||
|
||
def test_frequency_zero(): | ||
lamda = 0 | ||
|
||
assert fun.frequency_calculation(lamda) == 0 | ||
|
||
def test_frequency_int(): | ||
lamda = 2 | ||
|
||
assert fun.frequency_calculation(lamda) == 0.22507907903927654 | ||
|