Skip to content

Pin size-zero environments and moves onto the current location - #82

Merged
dmccoystephenson merged 1 commit into
masterfrom
feature/test-empty-grid-and-same-location-move
Nov 12, 2026
Merged

dmccoystephenson merged 1 commit into
masterfrom
feature/test-empty-grid-and-same-location-move

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • testEnvironmentOfSizeZeroHasNoLocationsAndLookupsThrow (Test 82) is added. An Environment of size 0 is shown to have no locations and zero entities. Grid::getLocation, Grid::getLocationByCoordinates, Environment::getFirstEntity, and Environment::getEntity are shown to throw std::runtime_error on it. addEntityToLocation with a separately constructed Location("0-0-0", 0, 0) is shown to place nothing and leave the entity's environment id and grid id at -1, and printConsoleRepresentation() is shown to print only a newline.
  • testMovingEntityToItsCurrentLocationLeavesItThere (Test 83) is added. moveEntityToNewLocation onto the entity's own location is shown to leave exactly one pointer (the entity's address) in that location, with its location, environment, and grid ids intact.
  • One sentence is added to the README's Errors section. It states which lookups stay safe on an empty grid, next to the existing note that getFirstLocation/getRandomLocation are undefined behaviour there.

This is a Stage B (unit-test expansion) cycle. Both tests describe current behaviour, and no production code is changed. Before this PR, neither a size-0 environment nor a same-location move had any test. No open issues existed at triage, so no skip reasons apply.

No tracking issue: the gap was found during triage.

Test plan

  • make compiles cleanly with the new tests (checked locally).
  • bash run_tests.sh and run_tests_asan.sh were not run locally, because running the test binary is denied in this sandbox. CI's Library tests (make + CMake) job is the anchor, and the merge waits on it.
  • Both new tests are registered in main().

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

Characterization tests for two untested boundaries: an environment of
size 0 has no locations, its id/coordinate/entity lookups throw, and
addEntityToLocation places nothing; moving an entity to the location it
is already in leaves exactly one pointer there with its ids intact.
README's Errors section now says which lookups stay safe on an empty grid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (anchored on CI run 43173835568, where Tests 82 and 83 print --- Success under run_tests.sh and run_tests_asan.sh, and ctest reports 100% passed):

  • Scope: PASS. Only src/tests.cpp (two tests plus their registration) and one README sentence on the same behaviour are changed.
  • Tests-new: PASS. No production method is added; both new tests exercise existing public methods.
  • Tests-fix: N/A. This is a characterization-only cycle with no bug fix and no src/*.cpp or header changes.
  • Sibling structure: PASS. Both tests follow the void test<Behavior>() / Test N - ... / --- Success pattern and continue the numbering from Test 81.
  • Sibling renames: N/A. Nothing is renamed.
  • Docs: PASS. The README Errors addition matches the code. Grid::getLocation and getLocationByCoordinates loop over an empty vector and throw (src/grid.cpp), Environment::getEntity and getFirstEntity throw after empty loops, and Grid::addEntityToLocation returns false. The ## Classes table is unaffected.
  • Issue resolution: N/A. No Closes references are used, because the gap was found during triage.
  • Local test suite: PASS through CI. Running the binary locally is denied in this sandbox, so Library tests (make + CMake) is the anchor, and it is green on the PR head.
  • Header/definition parity: N/A. No headers are touched.
  • Include guards: N/A. No new headers are added.
  • Test registration: PASS. Both functions are called from main(), and CI output shows them executing.

Minor observation (not blocking): src/tests.cpp, Test 82, does not assert that the entity's location id stays "N/S" after the failed addEntityToLocation. That property is already covered for the general unknown-location case by testAddingEntityToUnknownLocationLeavesIdsUnset, so it was not duplicated here.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 7f684af into master Nov 12, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/test-empty-grid-and-same-location-move branch November 12, 2026 07:18
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