Assignment study

Submit work that's clear, reproducible, and easy to grade.

The grader will clone your repo, run a single command, and expect tests to pass. This page is the canonical guide for writing clean, reproducible code.

Part 2

Working with the code

The grader will clone your repo, run a single command, and expect tests to pass. If they have to debug your environment for ten minutes before reading a single line, you've already lost marks. The goal is reproducibility.

Suggested project layout

repo layout
assignment-04-dijkstra/
├── README.md            # how to run, what to expect
├── requirements.txt     # pinned Python deps
├── src/
│   ├── __init__.py
│   ├── graph.py         # Graph class
│   └── dijkstra.py      # algorithm
├── tests/
│   ├── test_graph.py
│   └── test_dijkstra.py
├── inputs/
│   ├── small.txt
│   ├── edge.txt
│   └── stress.txt
└── report/
    ├── main.tex
    └── main.pdf

Reproducibility checklist

  1. 1Pin your dependencies — pip freeze > requirements.txt.
  2. 2Provide a one-command run: make test or pytest.
  3. 3Include sample inputs and expected outputs under inputs/.
  4. 4Commit the compiled main.pdf alongside the .tex source.
  5. 5Write a README that opens with: "To run, do X. To test, do Y."

Minimal test file

tests/test_dijkstra.py
from src.graph import Graph
from src.dijkstra import dijkstra

def test_simple_triangle():
    g = Graph()
    g.add_edge('A', 'B', 1)
    g.add_edge('B', 'C', 2)
    g.add_edge('A', 'C', 5)

    dist = dijkstra(g, 'A')
    assert dist['A'] == 0
    assert dist['B'] == 1
    assert dist['C'] == 3  # not 5 — the A->B->C path wins

def test_unreachable():
    g = Graph()
    g.add_edge('A', 'B', 1)
    # C is isolated
    g.adj['C']  # touch to register
    dist = dijkstra(g, 'A')
    assert dist['C'] == float('inf')
Style matters
Use type hints, docstrings on public functions, and meaningful variable names. distance_to_neighbor reads better than d in a report screenshot.

Ready to start?

Read the algorithm documentation first, then come back here to write up your findings.