Create Unit Tests for analyze_unsteady_trim in trim.py#183
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
==========================================
+ Coverage 91.77% 92.42% +0.64%
==========================================
Files 37 37
Lines 7234 7234
==========================================
+ Hits 6639 6686 +47
+ Misses 595 548 -47 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
camUrban
left a comment
There was a problem hiding this comment.
Hi @20086080, thanks for the work here. Your tests look great! I left a few suggestions for those, but the bigger thing is all the .idea file changes. We still don't want those modified or deleted or added to .gitignore. I think the best way to fix it is to follow the steps 1-6 from my comment here. The only thing to do different this time is to include the file names of all the .idea files and also .gitignore for step 2.
It seems like the steps I provided last time didn't quite work in getting your git install to ignore these. Therefore, in the future, I'd recommend not using git add . before committing. Instead, you can git add <file_1> <file_2> ... with the files you actually want to change, which should prevent your next git commit -m "<some message>" from picking up any extraneous changes. 😊
| @@ -0,0 +1,294 @@ | |||
| import unittest | |||
There was a problem hiding this comment.
Please add a module docstring (see other unit test files for the proper format). Also, you'll want to add this file's docstring to the list of docstrings in tests/unit/init.py and also import it there (in alphabetical order).
| boundsExternalFX_W=(10.0, -10.0), | ||
| ) | ||
|
|
||
| def test_objective_cut_off_validation(self): |
There was a problem hiding this comment.
It might be good to also add an assertRaises test on negative objective_cut_off values as well.
| objective_cut_off=0.0, | ||
| ) | ||
|
|
||
| def test_num_calls_validation(self): |
There was a problem hiding this comment.
For num_calls, we also want to throw out non-integer values and negative values.
There was a problem hiding this comment.
No need to add anything to this file.
|
Hi @camUrban I have added in the 2 test changes and doc string. Changes to be committed: Changes not staged for commit: |
|
Hi @20086080, thanks for reaching back out. Don't worry, you are mostly there! One quick question to be sure we're on the same page: When you ran step 1 from the comment, did you run it verbatim, or did you substitute the old branch name with the current branch? You can check by looking at the top few lines in your Once you're sure you are on the right branch, the next step is to also add the Once you've done that, you can just run a normal commit and push: After that, let me know if you have any other issues walking through step 8! |
Description
Add unit tests for analyze_unsteady_trim in trim.py covering parameter validation and operating point bounds validation.
These tests improve confidence in the trim analysis interface by verifying that invalid inputs are correctly rejected before optimization or solver execution begins.
Motivation
analyze_unsteady_trim contains extensive validation logic for user-supplied parameters and operating point constraints. These checks are critical because they prevent invalid optimization searches and ensure that trim analysis is only performed on well-defined UnsteadyProblem configurations.
The function was previously flagged with # TEST comments but did not have dedicated unit test coverage. Adding focused validation tests makes future refactoring safer and helps ensure that documented parameter requirements remain enforced.
Relevant Issues
Resolves unit testing component of #137
Changes
Added dedicated unit tests for analyze_unsteady_trim in test_unsteady_trim.py.
The following validation behavior is now tested:
test_problem_validation - Invalid problem parameter type raises TypeError.
test_multiple_airplane_movements_validation - Multiple AirplaneMovement objects raise ValueError.
test_boundsVCg__E_validation - Test boundsVCg__E parameter validation:
test_objective_cut_off_validation - Test objective_cut_off parameter validation.
test_num_calls_validation - Test num_calls parameter validation.
test_base_operating_point_parameter_bounds_validation - Test that the base operating point values must lie within the supplied boundss:
vCg__E
alpha
beta
externalFX_W
must lie within the user-supplied search bounds.
Testing Methodology
Tests use existing fixtures from tests.unit.fixtures.problem_fixtures to construct valid UnsteadyProblem instances.
The testing approach focuses on:
The tests intentionally avoid executing the optimization routines or aerodynamic solver, allowing validation logic to be tested in isolation as true unit tests.
Dependency Updates
None
Change Magnitude
Minor: Small change such as a bug fix, small enhancement, or documentation update.
Checklist (check each item when completed or not applicable)
mainand is up to date with the upstreammainbranch.--in-place --black). See the style guide for type hints and docstrings for more details.pterasoftwarepackage use type hints. See the style guide for type hints and docstrings for more details.testspackage.testspackage.ascii-only,black,codespell,docformatter,isort, andpre-commit-hooksGitHub actions.mypyGitHub action.testsGitHub actions.