This document describes the unit tests for the dashboard module functions: select_subject, select_date_range, and select_resolution.
The tests are written using Python's unittest framework.
The test_dashboard.py script contains unit tests for the following functions in the src.dashboard module:
select_subjectselect_date_rangeselect_resolution
These functions are used to filter and manipulate a DataFrame for a hypothetical dashboard application.
Functionality: This function filters a DataFrame to include only the specified subjects.
Test Case:
- Purpose: To ensure the function correctly filters the DataFrame based on a list of subject IDs.
- Setup:
- Create a test DataFrame
test_dfwith an 'Id' column. - Define a list of subject IDs
test_subjectto filter.
- Create a test DataFrame
- Execution: Call
select_subject(test_df, test_subject). - Assertion: Verify that the resulting DataFrame contains only the rows with the specified subject IDs.
Functionality: This function filters a DataFrame to include only the rows within a specified date range.
Test Case:
- Purpose: To ensure the function correctly filters the DataFrame based on a date range.
- Setup:
- Create a test DataFrame
test_dfwith a 'DateTime' column. - Define a start date
test_start_dateand an end datetest_end_datefor the range.
- Create a test DataFrame
- Execution: Call
select_date_range(test_df, test_start_date, test_end_date). - Assertion: Verify that the resulting DataFrame contains only the rows within the specified date range.
Functionality: This function aggregates the data in a DataFrame based on a specified time resolution (e.g., hourly).
Test Case:
- Purpose: To ensure the function correctly aggregates the DataFrame based on the specified resolution.
- Setup:
- Create a test DataFrame
test_dfwith 'Id', 'DateTime', and 'Steps' columns. - Define the resolution
test_resolutionto aggregate by (e.g., 'Hours').
- Create a test DataFrame
- Execution: Call
select_resolution(test_df, test_resolution). - Assertion: Verify that the resulting DataFrame correctly aggregates the 'Steps' data based on the specified resolution.