Skip to content

test: incidence() is checked cell by cell - #50

Merged
petercorke merged 1 commit into
mainfrom
test/incidence-positions
Oct 12, 2026
Merged

petercorke merged 1 commit into
mainfrom
test/incidence-positions

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Tests for incidence() that compare the matrix cell by cell. No source change.

0.6.5 returned the wrong matrix for every graph with an edge, from two bugs visible in its source:

for i, vertex in enumerate(self):            # i = vertex index
    for i, e in enumerate(vertex.edges()):   # reuses i: the edge's position in the vertex's list
        I[i, edict[e]] = 1
  1. the loop variable i is overwritten, so edges are marked in the wrong rows;
  2. only each vertex's own edges() are visited, so in a directed graph the vertex at the end of an edge is never marked.

Both were fixed in this cycle (the matrix is now built from edges() and both endpoints), but nothing pinned them: the existing tests check only column sums and row sums, because edges() was a set and the column order was undefined. It is now in the order the edges were added, so the matrix can be checked by position.

Tests

tests/test_incidence.py (32, both graph kinds), with each expectation written out by hand rather than derived from the code under test:

  • empty graph and vertices with no edges (shape)
  • a path, a star, edges pointing backwards, and a vertex that is only ever an edge's end (the two bugs)
  • rows follow vertex creation order, not names; columns follow the order edges were added, and are edges() order
  • parallel and antiparallel edges, undirected and directed loops (2 and 1)
  • columns close up after remove_edge, rows after remove_vertex, and an isolated vertex is a row of zeros

They discriminate: run against the real v0.6.5 source, 16 of the 16 that do not need newer API fail, all by assertion.

Also corrects a stale comment in test_graph.py that said the column order was not deterministic.

🤖 Generated with Claude Code

0.6.5 returned the wrong matrix for every graph with an edge: a loop variable
overwrote the vertex index, so edges were marked in the wrong rows, and for a
directed graph the vertex at the end of an edge was not marked.  The tests
that existed checked only column and row sums, because edges() was a set and
the column order was not defined, so neither bug was caught.

edges() is now in the order the edges were added, so the matrix can be
checked by position.  Each expectation is written out by hand, for both kinds
of graph: paths, a star, edges pointing backwards, a vertex that is only ever
an end, creation order against names, parallel and antiparallel edges, loops,
and rows and columns closing up after a removal.  16 of them fail on the
0.6.5 source.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 22 complexity · 0 duplication

Metric Results
Complexity 22
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.37%. Comparing base (6e2e81a) to head (96e5479).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage   95.37%   95.37%           
=======================================
  Files           3        3           
  Lines        1277     1277           
=======================================
  Hits         1218     1218           
  Misses         59       59           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke merged commit 6bff60e into main Oct 12, 2026
14 checks passed
@petercorke
petercorke deleted the test/incidence-positions branch October 12, 2026 03:33
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.

1 participant