Help Charlene to test her package (#31) (remember to commit after each step, if appropriate).
Choose who in your team is writing now! (make sure you've pulled the latest changes from your team's fork.)
Create a tests directory inside sagittal_average so it looks like
Desktop/ # if you cloned it there
└── sagittal_average/
├── .git/
├── pyproject.toml
├── sagittal_average/
└── tests/
Add a test similar to what we used last week when we discovered the bug.
Hint
You need a `test_something` function that runs all the below
1. Create an input dataset
```python
data_input = np.zeros((20, 20))
data_input[-1, :] = 1
```
1. Save it into a file
```python
np.savetxt("brain_sample.csv", data_input, fmt='%d', delimiter=',')
```
1. Create an array with expected result
```python
# The expeted result is all zeros, except the last one, it should be 1
expected = np.zeros(20)
expected[-1] = 1
```
1. call the function with the files
```python
run_averages(file_input="brain_sample.csv",
file_output="brain_average.csv")
```
1. Load the result
```python
result = np.loadtxt(TEST_DIR / "brain_average.csv", delimiter=',')
```
You can use Python's special variable `__file__` to point to the path where the data is read from.
1. Compare the result with the expected values
```python
np.testing.assert_array_equal(result, expected)
```
What could you do to make sure that these files we are creating don't interfere with our repository or the rest of the package?
Fix sagittal_brain.py (as you may remember from last week, the code wrongly averages over the columns, not the rows), make sure the test passes and commit these changes.
Try to install it by running pip install -e . where the pyproject.toml is, and then run the tests with pytest.
Share your solution as a pull request to Charlene's repository mentioning this issue (by including the text Addresses UCL-COMP0233-24-25/RSE-Classwork#32 in the pull request description), remember to mention your team members too! (with @github_username)
Help Charlene to test her package (#31) (remember to commit after each step, if appropriate).
Choose who in your team is writing now! (make sure you've pulled the latest changes from your team's fork.)
Create a
tests
directory insidesagittal_average
so it looks likeAdd a test similar to what we used last week when we discovered the bug.
Hint
You need a `test_something` function that runs all the below 1. Create an input dataset ```python data_input = np.zeros((20, 20)) data_input[-1, :] = 1 ``` 1. Save it into a file ```python np.savetxt("brain_sample.csv", data_input, fmt='%d', delimiter=',') ``` 1. Create an array with expected result ```python # The expeted result is all zeros, except the last one, it should be 1 expected = np.zeros(20) expected[-1] = 1 ``` 1. call the function with the files ```python run_averages(file_input="brain_sample.csv", file_output="brain_average.csv") ``` 1. Load the result ```python result = np.loadtxt(TEST_DIR / "brain_average.csv", delimiter=',') ``` You can use Python's special variable `__file__` to point to the path where the data is read from. 1. Compare the result with the expected values ```python np.testing.assert_array_equal(result, expected) ``` What could you do to make sure that these files we are creating don't interfere with our repository or the rest of the package?Fix
sagittal_brain.py
(as you may remember from last week, the code wrongly averages over the columns, not the rows), make sure the test passes and commit these changes.Try to install it by running
pip install -e .
where thepyproject.toml
is, and then run the tests withpytest
.Share your solution as a pull request to Charlene's repository mentioning this issue (by including the text
Addresses UCL-COMP0233-24-25/RSE-Classwork#32
in the pull request description), remember to mention your team members too! (with@github_username
)Sample solution