Skip to content

Improve test coverage from 72% to 80% with 68 new test cases - #2

Merged
cookbook-ms merged 6 commits into
mainfrom
copilot/analyze-test-coverage
Apr 7, 2026
Merged

Improve test coverage from 72% to 80% with 68 new test cases#2
cookbook-ms merged 6 commits into
mainfrom
copilot/analyze-test-coverage

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Analyzed test coverage across the codebase and added targeted tests for undertested modules, focusing on edge cases, error handling, fallback paths, and alternative code branches.

Coverage improvements by module

  • comparison.py 39% → 99% — plot variants (linear scale, show_lines, empty graphs), level topology comparison, run_full_comparison
  • transformer_edges.py 75% → 100% — bipartite Chung-Lu fallback when star centers exceed available leaves
  • bus_type_allocator.py 79% → 98% — ratio validation, size-dependent defaults, entropy model 1, plot_entropy_pdf, _generate_random_assignment fallback when non-leaf nodes are insufficient
  • input_configurator.py 82% → 96% — _generate_optimized_degrees (dgln/dpl), _generate_transformer_simple, create_params with simple connection type
  • capacity_allocator.py 85% → 93% — heuristic table (ref_sys_id=0), no-generator edge case
  • generation_dispatcher.py 87% → 93% — alpha_mod != 0 branches (negative dispatch), empty generator handling, invalid ref_sys_id fallback
  • deg_dist_optimizer.py 85% → 93% — extreme parameter fallback, unknown dist_type errors, verbose output
  • transmission.py 76% → 84% — empty graph, refine_topology=True, _assign_betas empty case
  • reference_data.py 78% → 80% — invalid ID error, system name validation, PMF sum checks

Known uncovered areas (intentional)

  • visualization.py / visualization_old.py — interactive matplotlib widget code requiring display backends
  • reference_data.py lines 217–259 — ref_sys_id=3 path blocked by known data bug (inhomogeneous array rows, documented in existing xfail test)
  • deg_dist_optimizer.py lines 76–77 — dead except RuntimeWarning (numpy raises warnings, not exceptions)

Copilot AI and others added 6 commits April 7, 2026 12:22
Cover all previously untested code paths:
- Empty graph handling in plot_degree_comparison
- Linear scale (log_scale=False) and show_lines=True branches
- Custom graph parameters and pre-created axes
- No common voltage levels edge cases
- plot_level_topology_comparison full path
- plot_all_levels_comparison with single and multiple levels
- run_full_comparison integration test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: cookbook-ms <92166253+cookbook-ms@users.noreply.github.com>
- test_transformer_edges: 4 new tests covering the bipartite Chung-Lu
  fallback path (lines 105, 120, 138-156) with leftover X, leftover Y,
  both leftovers, and large-center-insufficient-leaves scenarios.
- test_transmission: 6 new tests covering _assign_betas empty case,
  allocate on empty graph, allocate with refine_topology=True,
  _generate_beta sorted output, _generate_beta no-zeros guard, and
  fallback ref_sys_id.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: cookbook-ms <92166253+cookbook-ms@users.noreply.github.com>
…ut_configurator

- test_reference_data: Add tests for invalid ref_sys_id (ValueError), system
  names, and PMF validation (Tab_2D_Pgmax sums to ~1). Covers else branch.
- test_bus_type_allocation: Add TestBusTypeAllocator class with 12 unit tests
  covering _normalize_ratio validation, _get_ratios size thresholds, custom
  bus_type_ratio, _calculate_bus_ratios empty case, entropy_model=1 path,
  _get_d_parameter branches, and allocate output.
- test_input_config: Add 8 tests covering _generate_optimized_degrees (dgln/dpl),
  _generate_transformer_simple, create_params with k-stars/simple connections,
  multiple levels, invalid connection index, and non-negative Poisson degrees.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: cookbook-ms <92166253+cookbook-ms@users.noreply.github.com>
…atcher, and deg_dist_optimizer

- test_capacity_allocator: Add 4 tests covering ref_sys_id=0 heuristic path,
  no-generator allocation, heuristic table shape, and n_gen=0 distribution
- test_generation_dispatch: Add 5 tests covering no-generator dispatch,
  empty uncommitted selection, alpha_mod!=0 path, zero-count alphas, and
  invalid ref_sys_id fallback
- test_deg_dist_optimizer: Add 6 tests covering extreme params fallback,
  unknown type errors, verbose output, power-law decreasing property, and
  objective function penalty behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: cookbook-ms <92166253+cookbook-ms@users.noreply.github.com>
@cookbook-ms
cookbook-ms marked this pull request as ready for review April 7, 2026 13:19
@cookbook-ms
cookbook-ms merged commit eecdd2d into main Apr 7, 2026
2 checks passed
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