Skip to content

Conversation

Copy link

Copilot AI commented Nov 12, 2025

Identified and consolidated duplicated patterns across the test suite into reusable utilities.

Changes

Created tests/conftest.py with shared utilities:

  • electron_energy_MeV_low() / electron_energy_MeV_high() fixtures - replaces duplicate fixtures in test_stopping.py (1000.0 MeV) and test_stopping_models.py (100.0 MeV)
  • assert_list_of_type(result, expected_type, expected_first_value=None) - consolidates repetitive validation pattern used in 5 functions across test_materials.py and test_particles.py

Refactored test_cartesian_product.py:

  • Extracted generate_test_args(size1, size2, size3) to eliminate duplicated random data generation across 3 test functions

Example

Before:

def test_get_ids():
    ids = pyamtrack.materials.get_ids()
    assert isinstance(ids, list)
    assert len(ids) > 0
    assert all(isinstance(id, int) for id in ids)
    assert ids[0] == 1

After:

def test_get_ids():
    ids = pyamtrack.materials.get_ids()
    assert_list_of_type(ids, int, expected_first_value=1)

Impact: 91 additions, 78 deletions across 6 files; ~32 lines of duplication eliminated

Original prompt

Find and refactor duplicated code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 12, 2025 18:35
Co-authored-by: grzanka <7374733+grzanka@users.noreply.github.com>
Co-authored-by: grzanka <7374733+grzanka@users.noreply.github.com>
Co-authored-by: grzanka <7374733+grzanka@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated test code into shared utilities Nov 12, 2025
Copilot AI requested a review from grzanka November 12, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants